valid? is not working in Rails 2.2.2

Vipin Vm
Mon, 01 Dec 2008 06:08:28 -0000

Hey,

I have a problem regarding the validation in rails 2.2.2. In my model
User has these conditions.

validates_presence_of :user_name, :password, :email, :display_name
validates_uniqueness_of  :email, :message => '' Already Exists in the
System.''

When i run this in rails 2.0.2 its working fine.

Loading development environment (Rails 2.0.2)
?> user = User.new
user = User.new
=> #<User:0x20e4140 @new_record=true,
@attributes={"user_name"=>nil,
"password"=>nil, "display_name"=>nil,
"email"=>nil,"created_on"=>nil,"modified_on"=>nil}>
>> user.valid?
user.valid?
=> false

But in 2.2.2 give error.

Loading development environment (Rails 2.2.2)
?> user = User.new
user = User.new
=> #<User id: nil, user_name: nil, password: nil, display_name: nil,
email: nil, created_on: nil, modified_on: nil>
>> user.valid?
user.valid?
ArgumentError: wrong number of arguments (3 for 2)
  from
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/validations.rb:66:in
`add''
  from
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/validations.rb:66:in
`add_on_blank''
  from
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/validations.rb:64:in
`each''
  from
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/validations.rb:64:in
`add_on_blank''
  from
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/validations.rb:517:in
`validates_presence_of''
  from
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:182:in
`call''
  from
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:182:in
`evaluate_method''
  from
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:166:in
`call''
  from
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:90:in
`run''
  from
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:90:in
`each''
  from
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:90:in
`send''
  from
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:90:in
`run''
  from
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:277:in
`run_callbacks''
  from
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/validations.rb:1029:in
`valid_without_callbacks?''
  from
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/callbacks.rb:286:in
`valid?''
  from (irb):11