Reputation: 1752
models associations are as below:
Model I
class TimeLog < ActiveRecord::Base
has_one :custom_time_field, :dependent => :destroy
end
Model II
class CustomTimeField < ActiveRecord::Base
belongs_to :time_log
end
Error details:
a = TimeLog.find(1)
a.custom_time_field
#returns => #<CustomTimeField id: 1, time_entry_id: 1, status: 'incomplete', start_time: "2000-01-01 11:24:00", end_time: "2000-01-01 11:24:00">
a.custom_time_field.update(1, :status => '') # returns undefined method `update'
However a.custom_time_field.update_attributes() works
Now i can use update_attributes also i can use save method by creating object
But Why cant i use update method in such case? this is useful when multiple attributes need to updated at a time.
Comments/Pointers?
Upvotes: 1
Views: 1379
Reputation: 15771
update
is a class method of your model. Call it this way:
CustomTimeField.update(1, :status => '')
Upvotes: 2