Search code examples
ruby-on-railsdevise

How do I enable :recoverable in Devise?


By default, the forgot password in Devise doesn't actually send a password reset link to email and I know the :recoverable module is what needs to be enabled/implemented.

I have tried searching for tutorials or guides in google and here in stackoverflow but no success.

Where can I find a good example or what code do I need to enable it?


Solution

  • To enable the recoverable module, pass it as a symbol to the devise method.

    # in user.rb
    
    devise :recoverable # add other modules, separated by commas
    

    For example, your devise configuration might look something like this.

    devise :database_authenticatable, :registerable, :confirmable, :recoverable
    

    You should also add reset_password_token and reset_password_sent_at columns to your users table. You can do it with a migration.

    rails g migration add_recoverable_fields_to_users
    

    And in the generated migration file, add the following.

    def change
      add_column :users, :reset_password_token, :string
      add_column :users, :reset_password_sent_at, :datetime
    end