Can someone tell me how to store the current date/time when someone
posts a comment on my blog? I could even update the comments table
after the comment is saved in the controller, but I’m not sure how to do
that either.
Thanks for any help…
Can someone tell me how to store the current date/time when someone
posts a comment on my blog? I could even update the comments table
after the comment is saved in the controller, but I’m not sure how to do
that either.
Thanks for any help…
Create a field called created_at and/or updated_at and Rails will do
it all automatically. Make sure it’s a datetime (that’s in postgres,
not sure what the mysql equivalent is).
You can also just make a datetime field called whatever you want, and
do something like:
comment.posted_at = Time.now
and save it yourself…but it’s easier/more railsy to just use the
“magic” fields created_at/updated_at.
Pat
Thanks, that was easy!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs