我使用Ruby enumerable來創建另一個模型的數組。該方法「companiesattending」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
我缺少什麼?
工作。謝謝。 – DaveG