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

しかし、ここでの問題は、コードを実行するとエラーが発生することです。 ここに画像の説明を入力

だから私は何をすべきかわからない。基本的に、データはデータベースから取得され、列名が Brand、Year、Model である Boat データベースに保存したいと考えています。

4

1 に答える 1

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'} %>
于 2015-04-15T17:03:06.867 に答える