AJS
2008-Jan-04 18:14 UTC
difference between self.field and self[:field] in model callbacks?
I have a before_save callback that does a bit of housekeeping to the model data before it''s saved. The Rails documentation often attests the use of self.field to change data before it''s saved, eg: def before_save self.payment_due ||= Time.now + 30.days end But in my case doing self.field=''something'' in the before_save doesn''t appear to make any difference. However it works with self[:field] which is the same as write_attribute(:field,''something'') Can someone explain what the difference is? (And ideally how self.@field fits into all this, too) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---