【发布时间】:2015-06-21 15:06:46
【问题描述】:
我有一个表格;
<%= form_for @boats do |f| %>
<%= f.collection_select(:brand, :brand_id, @brands, :id, :name, {:prompt => "Select a Brand"}, {:id => 'brands_select'}) %>
<%= f.collection_select(:year, :year_id, @years, :id, :name, {:prompt => "Select a Year"}, {:id => 'years_select'}) %>
<%= f.collection_select(:model, :model_id, @models, :id, :name, {:prompt => "Select a Model"}, {:id => 'models_select'}) %>
<%= f.submit "Create my account" %>
<% end %>
并且有控制器#index;
def index
@boats = Boat.new
@brands = Brand.all
@years = Year.all
@models = Model.all
end
但这里的问题是,当我运行代码时,它给出了一个错误;
所以我不知道该怎么做。基本上,数据来自数据库,我想将它们保存到列名为 Brand、Year 和 Model 的 Boat 数据库中。
【问题讨论】:
-
您给出的最后 2 个参数是 2 个不同的哈希,而不是只有一个。请改用
{:prompt => "Select a Brand", :id => 'brands_select'}。 -
谢谢@MrYoshiji。但现在又出现了一个错误:
NoMethodError in HomeController#index,undefined method merge' for :name:Symbol
标签: ruby-on-rails collection-select