Hi, I must be doing something dumb, but I can''t figure this out. The following code: customer = Customer.new(:name => ''Ray'', :date_created => Time.now.to_s(:db)) customer.save! Always results in the error ActiveRecord::RecordInvalid: Validation failed: Date created can''t be null Yet, this code works fine: customer = Customer.new(:name => ''Ray'') customer.date_created = Time.now.to_s(:db) customer.save! Is there something I''m doing wrong that is preventing me from putting everything in the new method? Any help would be appreciated. Cheers, Ray -- 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 -~----------~----~----~----~------~----~------~--~---
Raymond O''Connor wrote:> Hi, > I must be doing something dumb, but I can''t figure this out. > > The following code: > > customer = Customer.new(:name => ''Ray'', :date_created => > Time.now.to_s(:db)) > customer.save! > > Always results in the error ActiveRecord::RecordInvalid: Validation > failed: Date created can''t be null > > Yet, this code works fine: > customer = Customer.new(:name => ''Ray'') > customer.date_created = Time.now.to_s(:db) > customer.save! > > > Is there something I''m doing wrong that is preventing me from putting > everything in the new method?Have you excluded date_created from mass updates via attr_accessible or attr_protected? If so, the second method is the only way that currently works, however I''d like to see new_unsafe, create_unsafe, build_unsafe, attributes_unsafe=, and update_attributes_unsafe methods that bypass protection for use in internal processing. The other alternative is some problem with your Customer.initialize code. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Raymond O''Connor wrote:> Hi, > I must be doing something dumb, but I can''t figure this out. > > The following code: > > customer = Customer.new(:name => ''Ray'', :date_created =>Remember you can use "created_at" which will insert the date for you automatic :) -- 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 -~----------~----~----~----~------~----~------~--~---