ruby on rails - Display content through ActiveRecord_Association_CollectionProxy -


i have products model 'has_many' relationship microposts. likewise, microposts has 'belongs_to' relationship products. throught relationship want populate row in table available microposts product. can tell association works fine , rows have potential display content, "#micropost::activerecord_associations_collectionproxy:0x007fa5ba8b4d60" displayed instead of actual content.

micropost.rb

class micropost < activerecord::base   belongs_to :product   default_scope -> { order(created_at: :desc) }   validates :product_id, presence: true   validates :content, presence: true end 

product.rb

class product < activerecord::base before_save{ self.name = name.downcase.humanize} before_save{ self.oem = oem.downcase.humanize}  validates :ta_code,  presence: true, length: { maximum: 4, minimum: 3 } validates :tatr,  presence: true, length: { maximum: 4, minimum: 4 },       uniqueness: true validates :name,  presence: true validates :oem,  presence: true validates :kind,  presence: true validates :ta_type,  presence: true has_many :microposts end 

code

<% product.all.each |product| %> . . . <% if product.microposts.any? %>             <ul class="microposts">               <% product.microposts.each |micropost| %>               <li><%= micropost.content %></li>               <% end %>               </ul>             <%= link_to "update status", new_status_path(product_id: product.id), :method => :create %>             <% else %>             <%= link_to "update status", new_status_path(product_id: product.id), :method => :create %>             <% end %> 

you change display part following

<% product.all.each |product| %> . . .   <ul class="microposts">     <%product.microposts.each |micropost| %>       <li><%=micropost.content%></li>     <% end %>   </ul> 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -