Forum: Ruby on Rails valid? is not working in Rails 2.2.2

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Vipin V. (Guest)
on 2008-12-01 08:08
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
Rick (Guest)
on 2008-12-01 10:18
(Received via mailing list)
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
Vipin V. (Guest)
on 2008-12-01 11:56
Hi Rick

when i commented the following line, it worked fine.

validates_presence_of :user_name, :password, :email, :display_name

then what could be wrong?

Vipin
Conrad T. (Guest)
on 2008-12-01 12:26
(Received via mailing list)
On Mon, Dec 1, 2008 at 1:56 AM, Vipin Vm
<removed_email_address@domain.invalid>wrote:

>
>
Hey Vipin, are you using the same application code for both Rails 2.0.2
and
2.2.2
execution of your tests.  If so, did you update the configuration files
when
executing your application code against Rails 2.2.2?

-Conrad
Bobnation (Guest)
on 2008-12-01 19:31
(Received via mailing list)
It just seems like there are too many conditions being tossed at the
validation method from wherever you are setting up those variables.
Vipin V. (Guest)
on 2008-12-02 06:45
Hi All,

My project was started in 1.2.6 then i upgraded to 2.0.2. Last week i
updated it into 2.2.2. Then i got this problem. Then i again moved it
back to 2.0.2 and it worked fine. These are the changes i have made in
my config files.

in env.rb :-
RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION
config.time_zone = 'UTC'
config.threadsafe!

database.yml:-
pool: 10
wait_timeout: 10

when i upgraded to 2.2.2, got a new file called new_rails_defaults.rb in
initializers folder.

I created a new project in 2.2.2 and connected to my original db. its
also working fine.
Vipin V. (Guest)
on 2008-12-02 06:57
Hi guys...

First of all Sorry ... :( . i had a plugin called gloc-1.1.0 in my
vender/plugin. That was causing the problem.

Thanks guys,
Vipin
Bobnation (Guest)
on 2008-12-02 07:03
(Received via mailing list)
Glad to hear that it was cleared up.
This topic is locked and can not be replied to.