Skip to content

Commit

Permalink
Document model association has many groups, show a list of groups sha…
Browse files Browse the repository at this point in the history
…ring a document
  • Loading branch information
tmlee committed Jul 4, 2011
1 parent e2ab2c8 commit e668658
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def index

def show
@users = @document.users
@groups = @document.groups
super
end

Expand Down
1 change: 1 addition & 0 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Document < ActiveRecord::Base
has_many :user_documents, :dependent => :destroy
has_many :group_documents, :dependent => :destroy
has_many :users, :through => :user_documents
has_many :groups, :through => :group_documents


attr_accessible :uploader, :name, :file, :description
Expand Down
7 changes: 6 additions & 1 deletion app/views/documents/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@
- unless @users.blank?
= render :partial => 'users/list', :locals => {:users => resource.users}
- else
%p=t('members.blank')
%p=t('document.blank_users')
#groups
- unless @groups.blank?
= render :partial => 'groups/list', :locals => {:groups => @groups}
- else
%p=t('document.blank_groups')

0 comments on commit e668658

Please sign in to comment.