【发布时间】:2014-02-19 02:23:40
【问题描述】:
这是可怕的代码,我知道。当它基于集合中的每条记录时,如何将其移动到模型中?
<% @brands.each do |b| %>
<% booleans = Preference.columns.select { |c| c.type == :boolean }.map(&:name) %>
<% trues = booleans.select { |name| b.preference.send(name) == true } %>
<%= trues.to_sentence.humanize %>
<% end %>
【问题讨论】:
-
你想要完成什么?我很乐意提供帮助,但不是逆向工程
-
这会返回一个关联列的列表,这些列是真的。
-
抱歉,我想你会得到列表最后一个元素的结果,因为:trues = booleans.select { |name| b.preference.send(name) == true } 你不想使用“trues +=”吗?对不起,如果我错了。
-
它肯定会返回一个列表。
标签: ruby-on-rails ruby-on-rails-3 erb