0

i created a file seeds.rb indb/seeds.rb code for this file is

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

it is giving me error

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)

it is running for user because it is created in development database but when it come to line user2.confirm! it throws this undefined method error i am unable to point why for one instance confirm! method is running and for second instance it is showing undefined??

Leo Correa
  • 19,131
  • 2
  • 53
  • 71
mathlearner
  • 7,509
  • 31
  • 126
  • 189

1 Answers1

0

Confirm functions of devise come when you include the confirmable module in your model. From the looks of it, i don't think you have used that in your model.

your code should have a confirmable symbol like below

class User < ActiveRecord::Base

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

end
coderhs
  • 4,357
  • 1
  • 16
  • 25