1

我有一个表格;

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

但这里的问题是,当我运行代码时,它给出了一个错误; 在此处输入图像描述

所以我不确定该怎么做。基本上,数据来自数据库,我想将它们保存到列名是品牌、年份和型号的 Boat 数据库中。

4

1 回答 1

4

正确的参数顺序是:

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

IE:

<%= f.collection_select :brand_id, @brands, :id, :name, {prompt: 'Select a Brand'}, {id: 'brand_select'} %>
于 2015-04-15T17:03:06.867 回答