2

error: thrown from the form

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

I have ran rake db:migrate and all seems fine until the page is rendered. Any clues as to why this is throwing the error would be awesome. Thanks

iamtoc
  • 1,569
  • 4
  • 17
  • 24
  • 1
    In a console, if you do: `directory_member = DirectoryMember.first; directory_member.profession_id` what do you get? – Chris Salzberg Sep 25 '16 at 12:59
  • Show your directory_member and profession model – luissimo Sep 25 '16 at 13:30
  • 1
    The code seems fine - rather it seems that your server is not picking up the migration. You can it debug it by running `$ rails runner "puts DirectoryMember.column_names"` in the console. We may be able to help you better if you write the exact steps you took when you encountered the error. Are you testing this by looking at the page on the development server or production or even a minitest/rspec test? – max Sep 25 '16 at 14:12
  • Just got back to the office and ran the 'rails runner' suggestion. profession_id surprisingly showed up so i refreshed the page and all is working now, so without doing anything except let 4 hours elapse, seemed to fix whatever was not connecting, unless of course running that command reinitialized everything. – iamtoc Sep 25 '16 at 17:59

0 Answers0