Im learning rails and exploring a bit away from the book and creating a simple application with added functionality as i increase my knowledge. Im writing a simple blog application and i have a field in the form called date added, i don’t want this to be a field i want it to get the date from the server and place it in to the database automatically. How would i go about doing this? I was thinking of a hidden field but then unsure on how to process the date and insert it to the hidden field. Is this the wrong way of going about things?
Thanks in Advance,
Dean
Im learning rails and exploring a bit away from the book and creating a
Share
I would not use a hidden field, because even if it is hidden the user can manipulate this. I think the best way to solve this problem is, ignore the date in the form and add the date to you your model in the controller action right before saving the object:
But you don’t have to do any of this, because ruby on rails offers the two columns
created_atandupdated_at.created_atwill be set when the object gets created andupdated_atwill be set every time when you update this object.