2017-07-30 6 views
0

だから、私はこのエラーを受け取り、私のスキーマの国では文字列なので、なぜ動作するのかわかりません。なぜそれが選択した国を教えない#Rails NoMethodError 'country_select'

ため

未定義のメソッド `country_select」:

<%= simple_form_for(@studentapplication) do |f| %> 
    <%= f.error_notification %> 

    <div class="form-inputs" id="session-form"> 
     <%= f.input :first_name, required: true, autofocus: true, placeholder: "First Name", label:false %> 
     <%= f.input :last_name, required: true, autofocus: true, placeholder: "Last Name", label:false %> 
     <%= f.input :email, required: true, autofocus: true, placeholder: "Email", label:false %> 
     <%= f.input :sex, required: true, autofocus: true, placeholder: "Sex", label:false %> 
     <%= f.input :country, required: true, autofocus: true, placeholder: "Country", label:false %> 
     <%= f.input :city, required: true, autofocus: true, placeholder: "City", label:false %> 
    </div> 

    <%= f.button :submit, "Apply", class: "student-bordered" %> 
<% end %> 

エラーメッセージが私に語った:

は、ここに私のコードですか?

schema.rb

create_table "studentapplications", force: :cascade do |t| 
    t.string "first_name" 
    t.string "last_name" 
    t.string "email" 
    t.string "sex" 
    t.string "country" 
    t.string "city" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
end 

答えて

1

あなたは、フィールド名「国」を持っている場合は、simple_formはcountry_selectを使用しようとします:私のスキーマは次のようになりますので、私は国が選択する必要はありません。あなたは、次のコードを使用することにより、

<%= f.input :country, as: :text %> 

それとも、あなたは、あなたのsimple_form.rb初期化子で

config.input_mappings = { /country/ => :string } 
+0

面白いの行を追加することができますことをオーバーライドすることができます!ありがとう、私はそれを知らなかった。それはうまくいった。第2のものを説明してもらえますか?私はそれをして、それはまだ私にエラーを与えた。最初の1つは働いた! –

+0

simple_form.rbファイル内にconfig.input_mappings = {/ country/=>:string}を追加したら、コードに反映させるために、レールサーバーを再起動する必要があります。 –

関連する問題