我有一个带有嵌套属性Property的Article对象。 现在我想在show.html.erb的前面打印它
我可以打印所有属性,但是在最后我得到的输出看起来像是里面有所有对象的地图。我做错了什么?
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
以及浏览器中错误的html输出
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">]
答案 0 :(得分:2)
变化
<%= @article.properties.each do |property| %>
到
<% @article.properties.each do |property| %>
=
符号呈现以下语句,在本例中是您正在迭代的集合。