Hi: I have timestamps in virtually all of my tables. The timestamp I want to add is always the current time, whenever I create a record in a table. Is this the type of thing I can be setting in my models, without have to be worrying about it in my controller methods. And if so, how would i do that in the model? Any help you can provide would be appreciated! Thanks! Mike --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you include a datetime column called created_at, it will automatically be populated. Ditto for modified_at. Miked wrote:> Hi: > > I have timestamps in virtually all of my tables. The timestamp I want > to add is always the current time, whenever I create a record in a > table. Is this the type of thing I can be setting in my models, > without have to be worrying about it in my controller methods. And if > so, how would i do that in the model? > > Any help you can provide would be appreciated! Thanks! > > Mike > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> I have timestamps in virtually all of my tables. The timestamp I want > to add is always the current time, whenever I create a record in a > table. Is this the type of thing I can be setting in my models, > without have to be worrying about it in my controller methods. And if > so, how would i do that in the model? > > Any help you can provide would be appreciated! Thanks!If you have a field in your database table named updated_at that is :datetime, rails will automatically do it for you and you don''t need to do anything else anywhere. Similarly for created_at I''m sure there''s a way in your model to tell Rails to use a different column than updated_at, but search for updated_at for more details. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 12, 2007, at 1:47 PM, Miked wrote:> > Hi: > > I have timestamps in virtually all of my tables. The timestamp I want > to add is always the current time, whenever I create a record in a > table. Is this the type of thing I can be setting in my models, > without have to be worrying about it in my controller methods. And if > so, how would i do that in the model? > > Any help you can provide would be appreciated! Thanks! > > Mikehttp://api.rubyonrails.org/classes/ActiveRecord/Timestamp.html Just: add_column :my_table, :created_at, :datetime to each table and let ActiveRecord to the rest. You can also use updated_at to see modification times. If you want the date only, created_on/updated_on are the way to go. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---