Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Customize Devise Confirmable module?

I have my Rails app setup with Devise, but it's still in the development stages. I also have a Thor task that creates the default Admin user.

Problem is Devise won't let that admin user login to the site until the account is confirmed. Is there any way I can disable the confirmable module for the creation of specific users, such as Admin?

My Thor task:

class Setup < Thor
  desc "create_admin [EMAIL] [PASSWORD]", "Creates the administrative user."
  def create_admin(email = "[email protected]", password = "testpassword123")
    require File.expand_path('config/environment.rb') # load Rails environment
    admin = User.create(:email => email, :password => password, :password_confirmation => password)
    admin.assign_role :admin
    puts "Admin user (#{ email }) created."
  end
end
like image 483
neezer Avatar asked Mar 12 '26 14:03

neezer


1 Answers

Once your user is created you can call the devise provided confirm! method on it rather than updating the database directly. Eg.:

admin = User.create(:email => email, :password => password, :password_confirmation => password)
admin.assign_role :admin
admin.confirm!
like image 197
Kevin Ansfield Avatar answered Mar 14 '26 04:03

Kevin Ansfield



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!