Validates_length_of INCONSISTENT BEHAVIOR

In one app (Beast app example) the User class has a login validation :
validates_length_of :login, :minimum => 2
the users table has been created … with one record login ‘kadoudal’

create_table “users”, :force => true do |t|
t.column “login”, :string
t.column “email”, :string

I check with script/console => >> User.find(:first)
and I get the user
#<User:0x34e5e54 @attributes={“login”=>“kadoudal” …

In my app
I replicated the User class ( copied exactly same code)
I copied the ‘users’ table into my DB and the schema.db is exactly the
same…

I check with script/console => >> User.find(:first)
and I got an error !!

NoMethodError: You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.%
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/validations.rb:487:in
validates_size_of' from /usr/local/lib/ruby/gems/1.8/gems/gettext-1.9.0/lib/gettext/active_record.rb:85:invalidates_length_of’
from ./script/…/config/…/config/…/app/models/user.rb:6
from
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:203:in
load_file' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:342:innew_constants_in’
from
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:202:in
load_file' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:94:inrequire_or_load’
from
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:248:in
load_missing_constant' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:452:inconst_missing’
from
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:464:in
`const_missing’
from (irb):1

and the line 6 in models/user.rb is … validates_length_of
:login, :minimum => 2

where could be the origin of such different behavior ? (…)

thanks for your suggestions

kad

Kad K. wrote:

NoMethodError: You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.%
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/validations.rb:487:in
validates_size_of' from /usr/local/lib/ruby/gems/1.8/gems/gettext-1.9.0/lib/gettext/active_record.rb:85:in validates_length_of’
from ./script/…/config/…/config/…/app/models/user.rb:6
from

A guess: it has something to do with the validation message. Go check
out active_record/validations.rb:487, where your error is occurring.
You’ll see that the error is from calling % on an apparently nil string.
Are you sure you’re not passing an invalid :message or :too_short in the
options hash? Or perhaps, as the next level of the stack suggests,
GetText is messing around with it?

Try disabling GetText temporarily. If you can’t figure it out, post more
of your model so we can see what’s going on.

Chris K.
http://kampers.net

Chris K. wrote:

Kad K. wrote:

NoMethodError: You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.%
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/validations.rb:487:in
validates_size_of' from /usr/local/lib/ruby/gems/1.8/gems/gettext-1.9.0/lib/gettext/active_record.rb:85:in validates_length_of’
from ./script/…/config/…/config/…/app/models/user.rb:6
from

A guess: it has something to do with the validation message. Go check
out active_record/validations.rb:487, where your error is occurring.
You’ll see that the error is from calling % on an apparently nil string.
Are you sure you’re not passing an invalid :message or :too_short in the
options hash? Or perhaps, as the next level of the stack suggests,
GetText is messing around with it?

Try disabling GetText temporarily. If you can’t figure it out, post more
of your model so we can see what’s going on.

Chris K.
http://kampers.net

Thanks Chris
Very strange…

I modified the config/environments/development.rb (as per the beast
example, mine was different…)

=> config.cache_classes = true

and it runs ok … now figuring why is another step …