我为这个文件创建了一个文件种子.rb indb/seeds.rb 代码是
puts 'SETTING UP DEFAULT USER LOGIN'
user = User.create! :name => 'My Fir User', :email => 'rashmi@example.com', :password => 'please', :password_confirmation => 'please'
user.confirm!
user2 = User.create! :name => 'My Second User', :email => 'user2@example.com', :password => 'please', :password_confirmation => 'please'
user2.confirm!
puts 'New user created: ' << user.name
它给了我错误
rake aborted!
undefined method `confirm!' for #<User:0x934ab30>
/home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/activemodel-3.2.9/lib/active_model/attribute_methods.rb:407:in `method_missing'
/home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/attribute_methods.rb:149:in `method_missing'
/home/ritesh/Desktop/rails3-devise-rspec-cucumber/db/seeds.rb:10:in `<top (required)>'
/home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `load'
/home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `block in load'
/home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `load'
/home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/engine.rb:520:in `load_seed'
/home/ritesh/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:333:in `block (2 levels) in <top (required)>'
/home/ritesh/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `eval'
/home/ritesh/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)
它正在为用户运行,因为它是在开发数据库中创建的,但是当涉及到 user2.confirm 行时!它引发了这个未定义的方法错误,我无法指出为什么要确认一个实例!方法正在运行,第二个实例显示未定义?