collection_select中的Arguments错误数量错误

时间:2015-04-15 15:06:04

标签: ruby-on-rails collection-select

我有一张表格;

<%= 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

但问题在于,当我运行代码时,它会给出错误; enter image description here

所以我不知道该怎么做。基本上,数据来自数据库,我想将它们保存到Boat数据库,其中列名是Brand,Year和Model。

1 个答案:

答案 0 :(得分:4)

正确的参数顺序是:

method, collection, value_method, text_method, options = {}, html_options = {}

即:

<%= f.collection_select :brand_id, @brands, :id, :name, {prompt: 'Select a Brand'}, {id: 'brand_select'} %>