Devise - Recoverable (Password Reset)
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?
ardavis
Follower of Christ. Husband to my High School sweetheart. Computer Engineer at NASA's Kennedy Space Center. Ruby / Ruby on Rails enthusiast. B.S. in Computer Engineering from Kettering University.
Updated on June 04, 2022Comments
-
ardavis almost 2 years
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.
-
ardavis over 12 yearsThe problem remains. It won't let me access the reset password page without it. It'll complain that there isn't a route for the users/password/new. I originally thought that too, I found that information here: github.com/plataformatec/devise/wiki/…
-
ardavis over 12 yearsI think the main issue is the fact that I'm trying to extend the Devise::PasswordsController. I wish I didn't have to do this, the only thing I want is for the reset password page to not use my application layout.
-
ardavis over 12 yearsFor 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.
-
Dan about 9 yearsI know this is/was an old comment, but you can very easily override devise's layout by creating
app/views/layouts/devise.html.erb
layout file of your own. -
JosephK almost 9 yearsThanks for that comment and update to this info. I did not know that bit of rails-magic at the time of my post.