Prashant Tiwari
2006-Apr-05 13:24 UTC
[Rails] how to insert Current DateTime value into database?
Hi, I want to insert onto database the Current DateTime Value into database field "Store_date" with datatype (DATETIME). How to do tihs? I am usiing hidden variable into my form as follows:- ======================<%= hidden_field("store", "store_date", :value =>:datetime ) %> ====================== But when I m submmittng form I couldn''t find entry in store_date field. How to do this using hidden variable? Please help me. Prashant -- Posted via http://www.ruby-forum.com/.
Andrew Cherry
2006-Apr-05 13:28 UTC
[Rails] how to insert Current DateTime value into database?
If you simply want the time that a record was updated, simply add a field to the model table called "updated_at". It''ll auto-update on save. -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Prashant Tiwari Sent: 05 April 2006 14:25 To: rails@lists.rubyonrails.org Subject: [Rails] how to insert Current DateTime value into database? Hi, I want to insert onto database the Current DateTime Value into database field "Store_date" with datatype (DATETIME). How to do tihs? I am usiing hidden variable into my form as follows:- ======================= <%= hidden_field("store", "store_date", :value =>:datetime ) %> ====================== But when I m submmittng form I couldn''t find entry in store_date field. How to do this using hidden variable? Please help me. Prashant -- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
Larry White
2006-Apr-05 13:41 UTC
[Rails] how to insert Current DateTime value into database?
It''s not rails-y, but I like having the db take care of this. If you''re using migration maybe it doesn''t matter, but if you''re defining your tables first, then you could define them like so. updated TIMESTAMPTZ NOT NULL DEFAULT NOW(), -- TIMESTAMPTZ is postgresql-specific I believe. This covers you if you have ever have non-ruby/rails updates to the table. Is this basically what rails does under the covers? thanks. On 4/5/06, Andrew Cherry <andrew.cherry@dreamteam.co.uk> wrote:> > If you simply want the time that a record was updated, simply add a > field to the model table called "updated_at". It''ll auto-update on save. > > > -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Prashant > Tiwari > Sent: 05 April 2006 14:25 > To: rails@lists.rubyonrails.org > Subject: [Rails] how to insert Current DateTime value into database? > > Hi, > > I want to insert onto database the Current DateTime Value into database > field "Store_date" with datatype (DATETIME). How to do tihs? > > I am usiing hidden variable into my form as follows:- > ======================= <%= hidden_field("store", "store_date", :value > =>:datetime ) %> ======================> > But when I m submmittng form I couldn''t find entry in store_date field. > > How to do this using hidden variable? > > Please help me. > Prashant > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060405/e9c5861b/attachment-0001.html
Alan Francis
2006-Apr-05 14:09 UTC
[Rails] Re: how to insert Current DateTime value into database?
Prashant Tiwari wrote:> Hi, > > I want to insert onto database the Current DateTime Value into database > field "Store_date" with datatype (DATETIME). How to do tihs? > > I am usiing hidden variable into my form as follows:- > ======================> <%= hidden_field("store", "store_date", :value =>:datetime ) %> > ======================> > But when I m submmittng form I couldn''t find entry in store_date field. > > How to do this using hidden variable? > > Please help me. > PrashantPrashant, please look at the documentation regarding created_on and updated_on. There'' is no need to use a hidden field for thuis as rails will automatically update certion fields for you. See, for example, http://wiki.rubyonrails.org/rails/pages/MagicFieldNames As regards the hidden field, a quick google for "ruby on rails hiden_field documentation" returned this: http://railsmanual.org/module/ActionView%3A%3AHelpers%3A%3AFormHelper#hidden_field It looks like you''re attempting to specify the data type (:datetime) in the value field. Is that correct ? Alan -- Posted via http://www.ruby-forum.com/.