Valid? is not working in Rails 2.2.2


#1

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:inadd_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:inadd_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:incall’
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:incall’
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:ineach’
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:inrun’
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:invalid_without_callbacks?’
from
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/callbacks.rb:286:in
`valid?’
from (irb):11


#2

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


#3

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


#4

On Mon, Dec 1, 2008 at 1:56 AM, Vipin Vm
removed_email_address@domain.invalidwrote:

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


#5

It just seems like there are too many conditions being tossed at the
validation method from wherever you are setting up those variables.


#6

Hi guys…

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

Thanks guys,
Vipin


#7

Glad to hear that it was cleared up.


#8

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.