Camilo.Orozco
Camilo.Orozco

Reputation: 287

How To Recover a Password with Devise ( Ruby on Rails)

I'm trying to recover a user's password with devise, but it generates the following error

undefined method `reset_password_sent_at=' for #<User:0x007fb78cfafb68>

Can anyone help me with this, since I'm new to Ruby on Rails?

What is the best way to recover a password and email the user using Devise? Thank you very much...

I'm use devise (2.2.3)

User.rb

require 'digest/md5'

class User < ActiveRecord::Base


  # Setup accessible (or protected) attributes for your model
  belongs_to :shop

  before_create :compute_email_md5

  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable,
    :recoverable,
    :rememberable,
    :trackable,
    :validatable,
    :token_authenticatable


  # Setup accessible (or protected) attributes for your model
  attr_accessible :email,
    :email_md5,
    :password,
    :password_confirmation,
    :shop_id,
    :role,
    :terms,
    :name,
    :notify_on_order_received

  validates :terms, :acceptance => true, :on => :create
end

THE SOLUTION IS add reset_password_sent_at column to user table

Upvotes: 4

Views: 963

Answers (1)

MrTheWalrus
MrTheWalrus

Reputation: 9700

As you've discovered, passord recovery requires that the model have a reset_password_sent_at column. Adding it via migration should solve this problem.

As for the reason this is happening, I'm guessing you added password recovery (the :recoverable module) after initially generating your Devise-enabled model (User). That's why Devise's generator didn't create that column for you.

Upvotes: 5

Related Questions