I was doing the following at the console to figure out why the created at attribute is not working. I found out the following:>> sr = StockReceiving.find :first=> #<StockReceiving:0x3651ce4 @attributes={"discount"=>"0", "modified_at"=>nil, "created_by"=>"admin", "purchase_order_id"=>"14", "supplier_invoice"=>"dfgfdg", "warehouse_id"=>"2", "id"=>"11", "modified_by"=>nil, "supplier_id"=>"1", "create d_at"=>"2006-11-11 18:11:17"}>>> sr=> #<StockReceiving:0x3651ce4 @attributes={"discount"=>"0", "modified_at"=>nil, "created_by"=>"admin", "purchase_order_id"=>"14", "supplier_invoice"=>"dfgfdg", "warehouse_id"=>"2", "id"=>"11", "modified_by"=>nil, "supplier_id"=>"1", "create d_at"=>"2006-11-11 18:11:17"}>>> sr.attributes=> {"discount"=>0.0, "modified_at"=>nil, "purchase_order_id"=>14, "created_by"=> "admin", "supplier_invoice"=>"dfgfdg", "warehouse_id"=>2, "id"=>11, "modified_by "=>nil, "supplier_id"=>1, "created_at"=>nil}>>When I show all the attributes of the object, it does not have a created_at attribute. I would like to know what''s goin on. Here is the model: class StockReceiving < ActiveRecord::Base has_many :details , :class_name => ''StockReceivingDetail'' def before_create self.warehouse_id = ''2'' self.created_by = ''admin'' end def before_update self.modified_by = ''admin'' self.modified_at = Date.now end end Thank you in advance. Junrey --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
See http://wiki.rubyonrails.com/rails/pages/Timestamping created_at, created_on, updated_at and updated_on, are handled automatically by ActiveRecord. Just create them as DATETIME fields. On 11/21/06, Junrey O. Beduya <jbeduya-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I was doing the following at the console to figure out why the created at > attribute is not working. > > I found out the following: > > > > >> sr = StockReceiving.find :first > > => #<StockReceiving:0x3651ce4 @attributes={"discount"=>"0", > "modified_at"=>nil, > > "created_by"=>"admin", "purchase_order_id"=>"14", > "supplier_invoice"=>"dfgfdg", > > "warehouse_id"=>"2", "id"=>"11", "modified_by"=>nil, "supplier_id"=>"1", > "create > > d_at"=>"2006-11-11 18:11:17"}> > > >> sr > > => #<StockReceiving:0x3651ce4 @attributes={"discount"=>"0", > "modified_at"=>nil, > > "created_by"=>"admin", "purchase_order_id"=>"14", > "supplier_invoice"=>"dfgfdg", > > "warehouse_id"=>"2", "id"=>"11", "modified_by"=>nil, "supplier_id"=>"1", > "create > > d_at"=>"2006-11-11 18:11:17"}> > > >> sr.attributes > > => {"discount"=>0.0, "modified_at"=>nil, "purchase_order_id"=>14, > "created_by"=> > > "admin", "supplier_invoice"=>"dfgfdg", "warehouse_id"=>2, "id"=>11, > "modified_by > > "=>nil, "supplier_id"=>1, "created_at"=>nil} > > >> > > > > When I show all the attributes of the object, it does not have a > created_at attribute. I would like to know > > what''s goin on. Here is the model: > > > > class StockReceiving < ActiveRecord::Base > > > > has_many :details , :class_name => ''StockReceivingDetail'' > > > > def before_create > > self.warehouse_id = ''2'' > > self.created_by = ''admin'' > > end > > > > def before_update > > self.modified_by = ''admin'' > > self.modified_at = Date.now > > end > > > > end > > > > > > > > Thank you in advance. > > > > Junrey > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rodrigo Alvarez wrote:> See http://wiki.rubyonrails.com/rails/pages/Timestamping > > created_at, created_on, updated_at and updated_on, are handled > automatically by ActiveRecord. Just create them as DATETIME fields.Or more specifically, the xxx_at should be DATETIME, the xxx_on should just be DATE. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 21 November 2006 18:55, Alan C Francis wrote:> Rodrigo Alvarez wrote: > > See http://wiki.rubyonrails.com/rails/pages/Timestamping > > > > created_at, created_on, updated_at and updated_on, are handled > > automatically by ActiveRecord. Just create them as DATETIME fields. > > Or more specifically, the xxx_at should be DATETIME, the xxx_on should > just be DATE.It''s only a convention. ActiveRecord won''t populate XXX_at or XXX_on fields with appropriate values (unless XXX is "created" or "updated"). --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---