ruby - Traversing Through Multiple Associations (Rails) -


i little stuck on one. appreciate input.

overview

i trying output require in friendship model i.e. files current user's friends have uploaded.

models

like other friendship models, user self-referencing :friend.

class share < activerecord::base     belongs_to :user     belongs_to :friend, :class_name => "user" end 

this paperclip model:

class upload < activerecord::base     belongs_to :user     has_attached_file :document end 

this 1 generated through devise:

class user < activerecord::base     attr_accessor :login      has_attached_file :image, :styles => { :medium => "120x120!" }      has_many :uploads     has_many :shares     has_many :friends, :through => :shares     has_many :inverse_shares, :class_name => "share", :foreign_key => "friend_id"     has_many :inverse_friends, :through => :inverse_shares, :source => :user end 

attempts

the furthest have gotten level in able output user's friends' :username(s), @check = current_user in controller:

<% @check.shares.each |j| %>         <%= j.friend.username %> <% end %> 

question

how output :file_name, :file_type, , :document of each of current user's friends? intend have page this:

user's friend 1 files

  • file name
  • file type
  • document

user's friend 2 files

  • file name
  • file type
  • document

thank you.

per paperclip documentation :

paperclip wrap 4 attributes (all prefixed attachment's name, can have multiple attachments per model if wish) , give them friendly front end. these attributes are:

<attachment>_file_name <attachment>_file_size <attachment>_content_type <attachment>_updated_at 

given that, , attachment name of "document" :

<% current_user.shares.each |share|%>     <%= share.friend.username %>     <% share.friend.uploads.each |upload| %>         <%= upload.document_file_name %>         <%= upload.document_content_type %>     <% end %> <% end %> 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -