Devise - Recoverable (Password Reset)

I am trying to allow the user to reset their password using the Devise recoverable option. This does not seem to work for me.

I am expanding Devise::PasswordsController so that it does not use the application layout.

 class PasswordsController < Devise::PasswordsController layout false end 

In my routes, I guarantee that my password controller is used.

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

Here is my user model, so you see that I have an option :recoverable .

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

On my login page, I have (I use haml):

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

This link correctly returns me to http://localhost:3000/users/password/new . Here is the form that is 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, it looks like it is trying to take me to the wrong place when I press the button. It does not work every time and does not show any messages in the server log.

It redirects me to: http://localhost:3000/passwords/user and tells me:

Routing error

 No route matches "/passwords/user" 

Any idea how I can proceed? I thought using a restored option should be easier than that. What am I doing wrong?

UPDATE For the record, I simply deleted everything that I did and tried to use standard development controllers, and I changed my application layout so that it did not cause errors, and everything works. So I just need a good way to remove the application layout from the reset password page.

+6
source share
2 answers

It seems that when you call password_path(resource_name) in your view code, the routing system thinks you mean /passwords/resource_name , not the controller name placed under users in Devise. This is because you have a string

 resources :passwords 

directly under your call to devise_for in your routes file. Now I'm not sure if this line exists for some reason, but does your problem go away when you comment on it?

+2
source

In the interest of those who find this old thread and want a different layout on some pages, I use this method in my /views/layouts/application.html.erb app to cross out the default layout.

 <% if ( current_page?(what_ever_path)) %> <div class="container"> <%= yield %> </div> <% else %> <%= render 'layouts/header' %> <div class="container"> <%= yield %> </div> <%= render 'layouts/footer' %> <% end %> 
0
source

Source: https://habr.com/ru/post/903923/


All Articles