Visit restful_authentication in seeds.rb

I am sure that I understand how seeds work in relation to seeds.rb, but I cannot use it to insert a restful_authentication user object into the database.

User.create(:login => 'admin', :role => Role.find_by_name('super_admin'), :email => ' admin@example.com ', :password => '123123') 

Did I miss something?

Edit: I also tried adding password confirmation. Still nothing.

+4
source share
3 answers

Try User.create!() Using the same options). This will show you any validation errors on the console.

+2
source

Password confirmation?

+1
source

Did you turn on the notification? If so, the User model is trying to send an email notification. If you have not configured your mail server, then the create operation will fail.

I had to do the following to solve this problem.

1 Change the user model

Add the dont_notify virtual attribute.

 class User < ActiveRecord::Base # add a attribute attr_accessor dont_notify end 

2 Modify the Observer code to detect the attribute.

 class UserObserver < ActiveRecord::Observer def after_create(user) return if user.dont_notify? #notice this line UserMailer.deliver_signup_notification(user) end def after_save(user) return if user.dont_notify? #notice this line UserMailer.deliver_activation(user) if user.recently_activated? end end 

3 Select dont_notify during sowing

In seed.rb set the flag.

 User.create(:login => 'admin', :role => Role.find_by_name('super_admin'), :email => ' admin@example.com ', :password => '123123', :password_confirmation => '123123', :dont_notify => true ) 
+1
source

Source: https://habr.com/ru/post/1302322/


All Articles