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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…