I have an app with categories ‘Active’, ‘Waitlist’, and ‘Terminated’. These are in the view as a select box.
When the user selects ‘Terminated’ I want to put the current date into a datetime attribute (in the same model).
What’s the best way to do this? I tried this, but it didn’t work, and I’m not sure it’s the right place to do it:
[in the controller]
def update
@household = Household.find(params[:id])
if @household.status.eql? 'Terminated'
@household.terminated = Date.yesterday()
end
if @household.update_attributes(params[:household])
....
end
end
Use after_update callback in your model:
EDIT:
Maybe better idea is to just get rid of status column and set terminated to date when it’s really terminated and to null when it’s not?