我正在使用 Ruby enumerable 从另一个模型创建一个数组。“公司参会”方式
class Conference < ActiveRecord::Base
has_many :accountconferences
has_many :accounts, :through => :accountconferences
accepts_nested_attributes_for :accounts
def companiesattending
accounts.collect {|f| f.name }
end
end
奇怪的是,当我把它放到一个视图中时,我得到了一个预期的项目列表,然后列表末尾的一些数组成员仍然在一个数组中:
查看结果
<ul style="list-style-type: none;">
<li>Company 1</li>
</ul>
<ul style="list-style-type: none;">
<li>Company 2</li>
</ul>
["3point5.com", "Company", "5.1", "A O Coolers", "Abo Gear", "Access Fund", "AceCamp.com", "ACORN"
/app/views/conferences/_accounts.html.erb
<div class="span5">
<h3 class="pull-left">Companies That Are Attending</h3></br></br></br>
<%= @accounts.each do |f|%>
<ul style="list-style-type: none;">
<li><%= f %></li>
</ul>
<% end %>
</div>
/app/models/conferences.rb(显示动作)
def show
@conference = Conference.find(params[:id])
@accounts = @conference.companiesattending
end
我错过了什么?