3
votes

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
3

3 Answers

6
votes

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!
2
votes

This should work

admin = User.create(:email => email, :password => password, :password_confirmation => password)

So your confirmed_at is set, which is the field devise refers to when checking user confirmation.

EDIT

Forgive me if this seems like a hack but this seems to work for me. After executing the above line,

admin.update_attributes(:confirmed_at => Time.now)
-1
votes

just coment :confirmable in User or Admin model

devise :database_authenticatable, :recoverable, :rememberable, :trackable, #:confirmable...

In config/inicializers/devise.rb you can set here how many time user have to confirm his account