Ruby Enumerable Collect Array仍显示在列表末尾 [英] Ruby Enumerable Collect Array still showing at end of list
本文介绍了Ruby Enumerable Collect Array仍显示在列表末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Ruby枚举来创建另一个模型的数组。 参加会议方法
I'm using Ruby enumerable to create an array of from another model. The method "companiesattending"
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
奇怪的是当我将其放入视图时,我得到了预期的项目列表,然后列表末尾的数组的某些成员仍在数组中:
What's strange is when I put this into a view I get a list of items as expected and then some of of the members of the array at the end of the list still in an array:
查看结果
<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
/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(显示操作)
/app/models/conferences.rb (Show Action)
def show
@conference = Conference.find(params[:id])
@accounts = @conference.companiesattending
end
我想念什么?
推荐答案
而不是:
<%= @accounts.each do |f|%>
在不使用 =
的情况下使用此功能:
Use this without =
:
<% @accounts.each do |f|%>
=
是代码显示的原因数组。
=
is the reason your code is displaying the array.
这篇关于Ruby Enumerable Collect Array仍显示在列表末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文