Reputation: 651
I have a Article object with nested attributes Property. Now I want to print it at the front in show.html.erb
I can print all attributes, but at the I get at the end an ouput that looks like a map with all objects inside. What am I doing wrong?
show.html.erb
<p>
<%= @article.properties.each do |property| %>
<li>
<b><%= property.name %></b> <%= property.value %>
</li>
<% end %>
</p>
article.rb
class Article < ActiveRecord::Base
has_many :properties
accepts_nested_attributes_for :properties
end
and the wrong html output in the browser
Property_6588 Value_6588
Property_9390 Value_9390
Property_15367 Value_15367
Property_19710 Value_19710
[#<Property id: 6588, name: "Property_6588", value: "Value_6588", article_id: 4766, created_at: "2012-04-12 13:33:23", updated_at: "2012-04-12 13:33:23">, #<Property id: 9390, name: "Property_9390", value: "Value_9390", article_id: 4766, created_at: "2012-04-12 13:33:29", updated_at: "2012-04-12 13:33:29">, #<Property id: 15367, name: "Property_15367", value: "Value_15367", article_id: 4766, created_at: "2012-04-12 13:33:41", updated_at: "2012-04-12 13:33:41">, #<Property id: 19710, name: "Property_19710", value: "Value_19710", article_id: 4766, created_at: "2012-04-12 13:33:50", updated_at: "2012-04-12 13:33:50">]
Upvotes: 0
Views: 146
Reputation: 17735
change
<%= @article.properties.each do |property| %>
to
<% @article.properties.each do |property| %>
The =
sign renders the following statement, in this case the collection you're iterating through.
Upvotes: 2