前提・実現したいこと
simple_formを使いフォームを実装する。
発生している問題・エラーメッセージ
simple_formを使いフォームを作っているのですが、
haml
1= simple_form_for @post, html: { multipart: true } do |f| 2 - if @post.errors.any? 3 #errors 4 %h2 5 = pluralize(@post.errors.count, "error") 6 prevented this picture from saving 7 %ul 8 - @post.errors.full_messages.each do |message| 9 %li= message 10 11 .form-group 12 = f.input :country, input_html: { class: 'form-control' } 13 .form-group 14 = f.input :description, input_html: { class: 'form-control' } 15 16 .form-group 17 = f.input :user_id, input_html: { class: 'form-control' } 18 19 = f.button :submit, class: "btn btn-info"
このコードを実行するとブラウザ上で以下のエラーがでます。
undefined method `country_select' for #<SimpleForm::FormBuilder:0x00007fcac6a7dc38>
countryメソッドが定義されていないということなのですが、schema.rb上にあるため、定義されているはずです。
rb
1ActiveRecord::Schema.define(version: 2020_01_27_100505) do 2 3 create_table "posts", force: :cascade do |t| 4 t.text "description" 5 t.string "country" 6 t.datetime "created_at", precision: 6, null: false 7 t.datetime "updated_at", precision: 6, null: false 8 t.integer "user_id" 9 end 10 11end
descriptionだけだとブラウザで表示されるので、問題なのはcountryです。
しかしモデル作成時にdescriptionとcountryを同時に与えているのに、なぜcountryだけがダメなのか理解できません。
またその後、追加でuser_idを与えているのですが、こちらは表示されます。
なぜcountryだけがエラーになるのでしょうか?
補足情報(FW/ツールのバージョンなど)
gem 'simple_form', '> 5.0', '>= 5.0.1'> 6.0.2', '>= 6.0.2.1'
ruby '2.6.3'
gem 'rails', '

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。