I am using bcrypt-ruby for password encryption. In the documentation for the gem http://bcrypt-ruby.rubyforge.org/ they give an action to allow someone to reset their password. I am trying to implement this action.
I added the following code on my login page:
<p>Forgot your Password? <%= link_to "Click to reset your password", forgot_password_session_path, confirm: "Do you really want to reset your password?" %></p>
Here is the code in my sessions_controller.rb file:
def forgot_password
random_password = Array.new(10).map { (65 + rand(58)).chr }.join
case
when User.find_by_email(params[:session][:email_user])
user = User.find_by_email(params[:session][:email_user])
when User.find_by_username(params[:session][:email_user])
user = User.find_by_username(params[:session][:email_user])
end
user.password = user.password_confirmation = random_password
user.save!
Mailer.create_and_deliver_password_change(user, random_password)
end
Here is the definition in config/routes.db:
resources :sessions do
member do
get "forgot_password"
end
end
Here is the output from rake routes:
forgot_password_session GET /sessions/:id/forgot_password(.:format) sessions#forgot_password
When I try to click on the link on my login link I get the following error:
No route matches {:action=>"forgot_password", :controller=>"sessions"}
I do not know how it says no route matches when it appears that it does. I have restarted my rails server & spork but still get the error. I do not know the next step.
Any help will be appreciated.
Update 5/26/2012 9:14 am GMT-6:
I changed to POST, restarted my rails server & Spork. I got the same error. Here is my log from the server:
Started GET "/login" for 127.0.0.1 at 2012-05-26 09:13:36 -0500 Processing by SessionsController#new as HTML Rendered sessions/new.html.erb within layouts/application (112.4ms) Completed 500 Internal Server Error in 116ms
Here is the rake routes info:
forgot_password_session POST /sessions/:id/forgot_password(.:format) sessions#forgot_password