Ruby on Rails - recover password on email NoMethodError -
i'm setting reset password feature. upon submission email sent reset password link. i'm doing scratch described in railscast episode 274. however, when submit email error.
nomethoderror in passwordresetscontroller#create
undefined method `password_reset_sent_at=' # <user:0xa9fd828> app/models/user.rb:26:in `send_password_reset' app/controllers/password_resets_controller.rb:7:in `create'
request
parameters:
{"utf8"=>"✓", "authenticity_token"=>"hnub/j15xztz3mtcd25mcwm06m3g2abcrh+cfxzdj+8=", "email"=>"cauterise@gmail.com", "commit"=>"reset password"}
the development log says same thing above ^
app/models/user.rb
def send_password_reset generate_token(:password_reset_token) self.password_reset_sent_at = time.zone.now save! usermailer.password_reset(self).deliver end def generate_token(column) begin self[column] = securerandom.urlsafe_base64 end while user.exists?(column => self[column]) end
app/controllers/password_resets_controller.rb
class passwordresetscontroller < applicationcontroller def new end def create user = user.find_by_email(params[:email]) user.send_password_reset if user redirect_to root_url, :notice => "email sent password reset instructions." end def edit @user = user.find_by_password_reset_token!(params[:id]) end def update @user = user.find_by_password_reset_token!(params[:id]) if @user.password_reset_sent_at < 2.hours.ago redirect_to new_password_reset_path, :alert => "password reset has expired." elsif @user.update_attributes(params[:user]) redirect_to root_url, :notice => "password has been reset!" else render :edit end end end
app/controllers/application_controller.rb
def current_user @current_user ||= user.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
app/vies/password_resets/new,html.haml
%h1 reset password = form_tag password_resets_path, :method => :post .field = label_tag :email = text_field_tag :email, params[:email] .actions = submit_tag "reset password" end
i did rake:db:reset , rake:db:migrate , reset server.
edit: db user
id integer primary key
email varchar(255)
password_hash varchar(255)
password_salt varchar(255)
created_at datetime
updated_at datetime
auth_token varchar(255)
password_reset_token varchar(255)
password_reset_send_at datetime
it seems database users column password_reset_send_at should password_reset_sent_at. can change going migration files , simple change running
$ rake db:reset $ rake db:migrate