Re: valid? is not working in Rails 2.2.2

Rick
Mon, 01 Dec 2008 08:17:44 -0000

Hey back at you,

Ruby version	1.8.7 (powerpc-darwin9)
RubyGems version	1.3.1
Rails version	2.2.2
Active Record version	2.2.2
Action Pack version	2.2.2
Active Resource version	2.2.2
Action Mailer version	2.2.2
Active Support version	2.2.2
Application root	/Users/rick/test222
Environment	development
Database adapter	sqlite3
Database schema version	20081124180200

================
class User < ActiveRecord::Base
  validates_presence_of :first_name,
       :middle_initial, :last_name,
       :username, :date_of_birth, :email
  validates_uniqueness_of :email,
       :message => ''Already Exists in the System''

end

================
script/console
Loading development environment (Rails 2.2.2)
user = User.new
>> user = User.new
=> #<User id: nil, first_name: nil, middle_initial: nil, last_name:
nil, username: nil, date_of_birth: nil, email: nil, created_at: nil,
updated_at: nil>
>> user.valid?
=> false
>>

Rick

On Nov 30, 9:08 pm, Vipin Vm
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
> 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
> --
> Posted viahttp://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@googlegroups.com