jeudi 5 mars 2015

NoMethodError for relationship between models

I am setting up a relationship between two of my models. A Patient Model and Worklist Model. My patient can belong to a worklist and a worklist can have many patients. In my form for patients I want to be able to select the worklist from a dropdown menu. I created a method in the form but its throwing an error. Here is my code:


from _form.html.erb:



<div class="field">
<%= f.label :worklist_id %>
<%= worklist_select( :patient, :worklist_id, Worklist.all, :id, :name, {}, { :multiple => false } ) %>
</div>


from patient.rb:



class Patient < ActiveRecord::Base
belongs_to :worklist
end


from worklist.rb



class Worklist < ActiveRecord::Base
has_many :patients
end


from schema.rb



create_table "patients", force: :cascade do |t|
t.string "lastname"
t.string "middlename"
t.string "firstname"
t.date "birthdate"
t.string "sex"
t.string "ethnicity"
t.string "uniqueid"
t.string "accountnumber"
t.string "medicaidid"
t.string "medicareid"
t.string "ssn"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "worklist_id"
end


And this is the error I am getting:



NoMethodError in Patients#edit
undefined method `worklist_select'

Aucun commentaire:

Enregistrer un commentaire