I'm working on a list where a checkbox indicates completion of an item, and a completion_date is populated with the current date/time if the checkbox is checked. My method is:
def complete
@task = Task.find(params[:id])
if @task.complete == nil || @task.complete == false
@task.update(complete: true)
@task.update(completion_date: Date.today)
redirect_to task_path
else
redirect_to task_path
end
end
So if the box is checked, the date is filled. However, I want my users to be able to uncheck the checkbox, and therefore void the timestamp.
I'm a rails newbie. Any help greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire