You'd probably do a before_save callback in the model checking if
completed is changed. If yes, set your completed_at time to
appropriate value. Something like:
before_save :update_completed_at_date
def update_completed_at_date
if completed_changed?
if completed?
completed_at = Date.today
else
completed_at = nil
end
end
end
Check the rails doc on active record if you need more info on the
callback process. There's a lot of different hook points and
depending on what version of rails, you might need to do something
different for checking if it's changed.
On Jun 26, 1:35 pm, bcavileer <[email protected]> wrote:
> I'm trying to do something pretty trivial here and I haven't had any
> luck searching the groups and tutorials.
>
> My model has a boolean field called 'completed', and a datetime field
> called 'completed_at'
>
> When the 'update' method in the controller is called, I'd like it to..
>
> if the user has set 'completed' == true, set completed_at = Date.today
> If the user has set 'completed' == false, set completed_at = nil
>
> Would some nice person please explain to me how this would be done?
> Do I put this in the controller or the model?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---