最佳答案
Question: when do I need to use self in my models in Rails?
I have a set
method in one of my models.
class SomeData < ActiveRecord::Base
def set_active_flag(val)
self.active_flag = val
self.save!
end
end
When I do this, everything works fine. However, when I do this:
class SomeData < ActiveRecord::Base
def set_active_flag(val)
active_flag = val
save!
end
end
The active_flag value doesn't change, rather it fails silently. Can someone explain?
I can't find any duplicates, but if someone finds one that's fine too.