对象字符串正在Rails 4.1中打印为HTML流

对象字符串正在Rails 4.1中打印为HTML流,html,ruby,erb,ruby-on-rails-4.1,Html,Ruby,Erb,Ruby On Rails 4.1,我在Rails(4.1)中有几个简单的多态关系。地址和电话对象可以属于个人或组织对象。所有的管道似乎都正常工作-积垢操作都正常工作,我的所有测试都通过了。 个人和组织的显示操作都包括一个分部,该分部应显示相关的地址和电话。虽然这些字段显示正确,但整个Ruby对象也在HTML流中呈现为字符串,这当然是有问题的。 PeopleController的显示操作: def show @addressable = @person @addresses = @addressable.addre

我在Rails(4.1)中有几个简单的多态关系。地址和电话对象可以属于个人或组织对象。所有的管道似乎都正常工作-积垢操作都正常工作,我的所有测试都通过了。 个人和组织的显示操作都包括一个分部,该分部应显示相关的地址和电话。虽然这些字段显示正确,但整个Ruby对象也在HTML流中呈现为字符串,这当然是有问题的。 PeopleController的显示操作:

def show
    @addressable = @person
    @addresses = @addressable.addresses

    @phoneable - @person
    @phones = @phoneable.phones
end
@person变量是在before_操作中使用私有函数设置的:

def set_person
    @person = Person.find(params[:id])
end
用于个人的show.html.erb(仅地址和电话部分):

地址

each
返回您正在调用的内容
each
因此:

@addresses.each { ... } == @addresses
用于插值,因此:

<%= @addresses.each do |address| %>

要评估(而不是插值)每个

谢谢您的捕获。我盯着代码看了这么久,我完全错过了显而易见的东西!
<h3>Addresses</h3>

  1 Viceroy Plaza<br>
  Suite 1300<br>
  Office 125<br>
  <br>
  Toronto, C8R 9G3<br><br>

  1313 Mockingbird Lane<br>
  Apt. 227<br>
  <br>
  <br>
  Mississauga, H3V 8Y4<br><br>
[#&lt;Address id: 2, address_line_1: &quot;1 Viceroy Plaza&quot;, address_line_2: &quot;Suite 1300&quot;, address_line_3: &quot;Office 125&quot;, address_line_4: nil, city: &quot;Toronto&quot;, postal_code: &quot;C8R 9G3&quot;, verified: false, use_for_contact: true, picture_file_name: nil, addressable_id: 1, addressable_type: &quot;Person&quot;, created_at: &quot;2014-04-13 20:32:41&quot;, updated_at: &quot;2014-04-13 20:32:41&quot;&gt;, #&lt;Address id: 1, address_line_1: &quot;1313 Mockingbird Lane&quot;, address_line_2: &quot;Apt. 227&quot;, address_line_3: nil, address_line_4: nil, city: &quot;Mississauga&quot;, postal_code: &quot;H3V 8Y4&quot;, verified: false, use_for_contact: true, picture_file_name: nil, addressable_id: 1, addressable_type: &quot;Person&quot;, created_at: &quot;2014-04-13 20:18:56&quot;, updated_at: &quot;2014-04-13 20:18:56&quot;&gt;]
  </br>
  <h3>Phones</h3>

  (1) 416-3219700<br><br>

  (1) 289-4346789<br><br>
[#&lt;Phone id: 2, country_code: &quot;1&quot;, area_code: &quot;416&quot;, phone_number: &quot;3219700&quot;, phone_extension: &quot;13125&quot;, verified: nil, use_for_contact: nil, phoneable_id: 1, phoneable_type: &quot;Person&quot;, created_at: &quot;2014-04-13 20:34:54&quot;, updated_at: &quot;2014-04-13 20:34:54&quot;&gt;, #&lt;Phone id: 1, country_code: &quot;1&quot;, area_code: &quot;289&quot;, phone_number: &quot;4346789&quot;, phone_extension: nil, verified: nil, use_for_contact: nil, phoneable_id: 1, phoneable_type: &quot;Person&quot;, created_at: &quot;2014-04-13 20:30:54&quot;, updated_at: &quot;2014-04-13 20:30:54&quot;&gt;]
@addresses.each { ... } == @addresses
<%= @addresses.each do |address| %>
<% @addresses.each do |address| %>