Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise:: Cannot create user through rake db:seed (failure confirmation_instructions)

User model has a function

def self.createadmin(
User.create(:email => "[email protected]", :password => "123456e", :password_confirmation => "123456e", :terms_of_service => '1')
end

In rake db:seed, I have to call User.createadmin

However, this fails

ActionView::Template::Error: ActionView::Template::Error
    from /Users/bever/Projects/tr/app/views/devise/mailer/confirmation_instructions.html.erb:3:in `_app_views_devise_mailer_confirmation_instructions_html_erb___1974818942364630283_2154906860'

Then I changed the code in createadmin

begin
User.create(:email => "[email protected]", :password => "123456e", :password_confirmation => "123456e", :terms_of_service => '1')
rescue => e
User.create(:email => "[email protected]", :password => "123456e", :password_confirmation => "123456e", :terms_of_service => '1')
end    

It works! Any clue why this is happening?

like image 768
Pykih Avatar asked Nov 04 '22 13:11

Pykih


1 Answers

Have you tried seeding from the db/seeds.rb file instead of the model? When you try to do it on the model, devise is probably trying to send the conformation mail.

You should create your admin user on the seeds.rb file like this

User.create(:email => "[email protected]", :password => "123456e", :password_confirmation => "123456e", :terms_of_service => '1')

Remember that if you are using confirmable module of devise you should add this field to the query.

:confirmed_at => Time.now

Maybe you should add the confirmation tokens and other fields useful to administrate your admin account via your rails app and not on the console.

PD: Probably if you post more of the error shown and maybe the line in the view I can help you more.

Greetings

like image 118
Core2Juan Avatar answered Nov 09 '22 06:11

Core2Juan