0
단어로 설명하기가 어렵지만 코드를 설명하고 함께 설명하겠습니다. 지금 나는 유닉스와 유사한 권한 시스템으로 응용 프로그램을 작성 중이며 한 가지 문제에 부딪혔다 고 말할 수 있습니다. 아직 해결 방법을 모르겠습니다. 아래는 관계가있는 모델입니다. 마음에 내 시스템으로모든 그룹 폴더 목록을 나열하십시오
class Document < ActiveRecord::Base
attr_accessible :name, :rights
belongs_to :folder
validates :folder_id, presence: true
end
class Folder < ActiveRecord::Base
attr_accessible :name, :rights
belongs_to :user
has_many :documents, dependent: :destroy
validates :name, presence: true
validates :user_id, presence: true
end
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation, :user_id
has_many :folders
has_many :group_users
has_many :groups, :through => :group_users
end
class Group < ActiveRecord::Base
attr_accessible :name, :owner
has_many :group_users
has_many :users, :through => :group_users, dependent: :destroy
end
class GroupUser < ActiveRecord::Base
attr_accessible :group_id, :user_id
belongs_to :user
belongs_to :group
end
, 그룹의 모든 사용자는 그룹 소유자가 소유하고있는 모든 폴더 (지금 계정에 권한을 복용하지)에 액세스 할 수 있어야합니다. 그리고 이것은 모든 폴더를 나열하려고 시도한 것입니다. 사용자가 액세스 할 수 있습니다. 사용자 자신이 그룹을 소유하는 경우 list_folder보기
<table class="table table-striped">
<tr>
<td>Folder name</td>
<td>Documents</td>
<td>Actions</td>
</tr>
<% for group in @user_groups %>
<% user = User.find(group.owner)%>
<% folders = user.folders %>
<% for folder in folders %>
<tr>
<td><%= folder.name %></td>
<td>#</td>
<td><%= link_to 'view', folder_path(folder.id) %></td>
<tr>
<% end%>
<% end %>
</table>
에서 폴더 컨트롤러
def list_folders
@user_groups = current_user.groups
end
에서
그래서 문제는 자신의 폴더를 가져올 aswell를 얻을, 지금 코드입니다. 사용자가 소유 한 폴더를보고 편집 할 다른 장소가 있기 때문에이 작업이 필요하지 않습니다. 여기서 나는 그가 다른 그룹에서 얻은 것을 가져오고 싶다. 나는 어쨌든 그를 질의에서 제외 시키려고했지만 성공하지 못했습니다. 그런 다음 그를 @user_groups 배열에서 제거하려고 시도했지만 원하는대로 작동하지 않았습니다. 나는이 문제에 대한 제안을하고 가능한 경우 반복자의 반복자 (또는주기?)가 나를 더러워 보이기 때문에 코드를 다시 작성하는 방법에 대한 힌트를 얻고 싶다.