Devise :: Unable to create user via rake db: seed (fail confirm_instructions)

The user model has a function

def self.createadmin( User.create(:email => " abc@gmail.com ", :password => "123456e", :password_confirmation => "123456e", :terms_of_service => '1') end 

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

However this does not work

 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 => " abc@gmail.com ", :password => "123456e", :password_confirmation => "123456e", :terms_of_service => '1') rescue => e User.create(:email => " abc@gmail.com ", :password => "123456e", :password_confirmation => "123456e", :terms_of_service => '1') end 

It works! Any clues why this is happening?

+4
source share
1 answer

Have you tried sowing from the db / seeds.rb file instead of the model? When you try to do this on a model, the developer is probably trying to send a confirmation message.

You must create your administrator in the seeds.rb file, like this

 User.create(:email => " abc@gmail.com ", :password => "123456e", :password_confirmation => "123456e", :terms_of_service => '1') 

Remember that if you use a confirmatory development module, you must add this field to the request.

 :confirmed_at => Time.now 

Maybe you should add confirmation tokens and other fields that are useful for administering your administrator account through your rails application, and not on the console.

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

Hello

+2
source

All Articles