I have the following method in my model
def reset_review_status
needs_review = true
save
end
There is an attribute on the model called needs_review, however when I debug it, it saves it as a new variable. If I do self.needs_review=true
, it works fine. I have no attr_accessible clause, although I do have one accepts_nested_attributes_for.
Any thoughts on why this might be happening?
When you define an attribute in ActiveRecord, the following methods are available
You can call the setter using
but this is the same way you set a variable. When you call the statement within a method, Ruby gives higher precedence to variables assignment, thus a variable with that name will be created.
As a rule of thumb:
self.method_name =
when you want to call the setter within a methodself.method_name
when a local variable with the same name exists in the context