未定义的方法`确认!'对于#<user> </user>

时间:2013-01-14 06:17:05

标签: ruby-on-rails devise ruby-on-rails-3.2 devise-confirmable

我创建了一个文件seeds.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! 它抛出这个未定义的方法错误 我无法指出为什么一个实例确认!方法正在运行,对于第二个实例,它显示未定义??

1 个答案:

答案 0 :(得分:0)

在模型中包含可确认模块时,确认设计功能。从它的外观来看,我认为你没有在你的模型中使用它。

您的代码应该有一个可识别的符号,如下所示

class User < ActiveRecord::Base

  devise :database_authenticatable, :registerable, :omniauthable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable

end