我有一个叫做Genre的模特
其中已经存储了许多记录。
我试图从“类型”表中获取所有记录,并在选择时全部显示。
请参阅下面的代码。
但这会返回这样的错误。我该如何解决?
:id:Symbol的未定义方法`map'
我的看法
<%= form_tag communities_path, :method => :get, :class => 'form-search' do %>
<div class="input-append">
<%= form.collection_select :id, Genre.all, :id, :name %>
<button type="submit" class="btn">Search</button>
</div>
<% end %>
最佳答案
collection_select
需要一个标识符作为第一个参数,并且在提供的示例中未设置变量form
。因此,代码应为:
<%= form_tag communities_path, :method => :get, :class => 'form-search' do %>
<div class="input-append">
<%= collection_select :genre, :id, Genre.all, :id, :name %>
<button type="submit" class="btn">Search</button>
</div>
<% end %>
关于ruby-on-rails - 我怎样才能正确地将选择集合放到form_tag中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14128721/