Chris Stump
2007-Feb-11 16:37 UTC
ActiveRecord::Validation#valid? throws strange ArgumentError
I''m running Rails 1.2.1 with Ruby 1.8.4. The following script/console session reveals the problem one of my models is suffering:>> r=Reminder.new=> #<Reminder:0xb73cf3d4 @new_record=true, @attributes={"receiver_id"=>nil, "sent_date"=>nil, "appt_date"=>nil, "notify"=>nil}>>> r.valid?ArgumentError: wrong number of arguments (1 for 0) from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/callbacks.rb:328:in `notify'' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/callbacks.rb:328:in `callback'' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/callbacks.rb:301:in `valid?'' from (irb):2 Here is my model: class Reminder < ActiveRecord::Base belongs_to(:receiver) validates_presence_of(:appt_date) validates_numericality_of(:notify) validates_presence_of(:receiver_id) end Here is my migration: def self.up create_table :reminders do |t| t.column(:appt_date, :datetime, :null => false) t.column(:notify, :integer, :null => false) t.column(:sent_date, :datetime) t.column(:receiver_id, :integer, :null => false) end add_index(:reminders, :receiver_id) end What gives? `r.valid?` should return false. I have similar, more complex setups with other models using validates_presence_of and validates_numericality_of and they do not throw ArgumentErrors. As expected, if I comment out the validates_* method calls the problem goes away. Any help is greatly appreciated! Thanks in advance ;) -- 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 -~----------~----~----~----~------~----~------~--~---
George Ogata
2007-Feb-12 12:24 UTC
Re: ActiveRecord::Validation#valid? throws strange ArgumentError
On 2/12/07, Chris Stump <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I''m running Rails 1.2.1 with Ruby 1.8.4. The following script/console > session reveals the problem one of my models is suffering: > > > >> r=Reminder.new > => #<Reminder:0xb73cf3d4 @new_record=true, > @attributes={"receiver_id"=>nil, "sent_date"=>nil, "appt_date"=>nil, > "notify"=>nil}> > >> r.valid? > ArgumentError: wrong number of arguments (1 for 0) > from > /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/callbacks.rb:328:in > `notify'' > ...Ouch! callbacks.rb:328 shows that #notify is an internally used private method. Your notify attribute is colliding with this. Try choosing another name (as unsatisfying as that solution probably seems...). --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---