'model'的未定义方法'数据库字段'

时间:2016-09-25 12:53:10

标签: ruby-on-rails actioncontroller

错误:从表单中抛出

undefined method `profession_id' for #<DirectoryMember:0xa12be40>

ENV:

Rails: 5.0.0.1
Ruby: 2.2.4

form.html.erb

<%= f.collection_select(:profession_id, @professions, :id, :title, {:include_blank => true, :prompt => true}) %>

的routes.rb

resources :directory_members

directory_members.rb

@professions = Profession.all.order(:title)

def directory_member_params
  params.require(:directory_member).permit(
  :user_id, 
  :directory_id, 
  :name, 
  :company, 
  :profession_id, 
  :address, 
  :phone, 
  :facebook, 
  :video, 
  :twitter, 
  :linkedin, 
  :google_plus, 
  :youtube
  )
end

schema.rb

create_table "directory_members", force: :cascade do |t|
  t.integer  "user_id"
  t.integer  "directory_id"
  t.string   "name"
  t.string   "company"
  t.text     "address"
  t.string   "phone"
  t.string   "facebook"
  t.string   "video"
  t.string   "twitter"
  t.string   "linkedin"
  t.string   "google_plus"
  t.string   "youtube"
  t.datetime "created_at",    null: false
  t.datetime "updated_at",    null: false
  t.integer  "profession_id"
end

我已经运行了rake db:migrate,在呈现页面之前一切正常。 关于为什么这会抛出错误的任何线索都会很棒。感谢

0 个答案:

没有答案