I have a polymorphic association relationship happening, and when I retrieve a record through it, such as:
hour = my_model.find( keeper_id ).hours.where( "day = ?", day_index )
Then try to call update_attributes on it:
hour.update_attribute(:start_time, start_time)
I get an error:
NoMethodError (undefined method `update_attribute' for #<ActiveRecord::Relation:0x0000010458c708>):
activerecord (3.0.0) lib/active_record/relation.rb:373:in `method_missing'
I assume it's because I retrieved the record through the relationship. How can I get around this?
Update attribute works on a single record, not on a collection.
Use update_all
instead (syntax is a little bit different).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With