Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise - Recoverable (Password Reset)

I am trying to allow the user to reset their password using Devise's recoverable option. This doesn't seem to be working for me.

I extend the Devise::PasswordsController so that it doesn't use the application layout.

class PasswordsController < Devise::PasswordsController
  layout false
end

In my routes, I ensure that my passwords controller is used.

devise_for :users, :controllers => {:passwords => "passwords"}
resources :passwords

Here's my User model so you see that I have the :recoverable option.

devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

On my login page, I have (I'm using haml):

...
= link_to "Forgot your password?", new_password_path(resource_name)

This link correctly takes me to http://localhost:3000/users/password/new.Here is the form that is found there:

%h2 Forgot your password?
= form_for(resource, as: resource_name, url: password_path(resource_name), html: { :method => :post }) do |f|
  = devise_error_messages!
  %div
    = f.label :email
    %br/
    = f.email_field :email
  %div= f.submit "Send me reset password instructions"

However, this seems to try to take me to the wrong place when I click the button. It's failing every time, and not showing any emails in the server log.

It's redirecting me to: http://localhost:3000/passwords/user and telling me:

Routing Error

No route matches "/passwords/user"

Any idea how I can proceed? I thought using the recoverable option was meant to be easier than this. What am I doing wrong?

UPDATE For the record, I just removed everything I did, and tried using the standard devise controllers, and I modified my application layout so that it wouldn't cause an error, and everything is working. So I just need a good way to remove the application layout from the password reset page.

like image 660
ardavis Avatar asked Dec 16 '11 16:12

ardavis


1 Answers

It seems to be that when you call password_path(resource_name) in your view code, the routing system thinks you mean /passwords/resource_name, rather than the controller namespaced under users by Devise. This is because you have the line

resources :passwords

directly under your devise_for call in your routes file. Now I'm not sure if that line is there for a reason, but does your problem go away when you comment it out?

like image 66
Leo Cassarani Avatar answered Oct 19 '22 03:10

Leo Cassarani