set activated_at only when active is updated to true

I've just added a couple of fields to one of our models (Resource): active (boolean) and activated_at (datetime).

I want to set it up so that if i make a restful call to update, and set active to true, ie

"/resources/15?active=true" [PUT]

then activated_at is automatically set to Time.now.

I can't quite work out how to set this up though...it's almost like a before_save, where i check if active was JUST SET to true, or we just got a request to make it true, as opposed to simply testing if it's true.

I'm sure this is slap-my-head obvious - anyone?

thanks max

I've just added a couple of fields to one of our models (Resource): active (boolean) and activated_at (datetime).

I want to set it up so that if i make a restful call to update, and
set active to true, ie

"/resources/15?active=true" [PUT]

then activated_at is automatically set to Time.now.

I can't quite work out how to set this up though...it's almost like a before_save, where i check if active was JUST SET to true, or we just got a request to make it true, as opposed to simply testing if it's true.

Does the dirty changes tracking in rails 2.1 help you?

Fred

Frederick Cheung wrote:

well you could do something like

def active=(value)   self.activated_at = Time.now if value && !active?   self[:active]=value end

Frederick Cheung wrote:

def active=(value)   self.activated_at = Time.now if value && !active?   self[:active]=value end

perfect - thanks Frederick!