user2284821
user2284821

Reputation: 431

How to assign values for update_attributes in rails?

I have a noob question about assigning values using update_attributes.

In the exam controller, a new exam record is saved and then an patient record is retrieved which matches some of the new exam fields. This part works fine.

@exam.save

@patient = Patient.joins(:charts).where(:dob => @exam.patient_dob).where(:charts => { :provider_id => @exam.provider_id, :patient_mrn => @exam.patient_mrn }) 

Then i try to update the new @exam record with a value from the @patient record using the following which crashes and burns......

@exam.update_attributes(:patient_id, @patient.id)

How have i gone so far astray?

Upvotes: 0

Views: 303

Answers (1)

sevenseacat
sevenseacat

Reputation: 25029

You're updating a single value there, not multiple values, so update_attribute would be more appropriate. update_attributes takes a hash of values to update.

See http://apidock.com/rails/ActiveRecord/Base/update_attribute and http://apidock.com/rails/ActiveRecord/Persistence/update_attributes

Upvotes: 2

Related Questions