Forum: Ruby on Rails easy before_update question (i hope)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eecd295cdec2454c66e2015036a39408?d=identicon&s=25 Scott Nj (scottnj)
on 2008-11-10 10:02
(Received via mailing list)
in a before_update is there an easy way to check if a specific field
is being changed?

for example

def before_update
  unless current.email == new.email
    # do stuff
  end
end

obviously "current.email" and "new.email" are wrong. i am guessing one
will be "self.email", what would the other be?
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-10 11:08
(Received via mailing list)
On 10 Nov 2008, at 09:02, scott wrote:

> end
>
> obviously "current.email" and "new.email" are wrong. i am guessing one
> will be "self.email", what would the other be?

from 2.1 onwards you'll get an email_changed? method for free.

Fred
This topic is locked and can not be replied to.