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:in
validates_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:in
new_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:in
require_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:in
const_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