13

I need my Rails app to redirect to the home page after I submit the email to send me reset password instructions. Devise, by default renders the sign in form after entering the email.

So I am trying to override the Devise::PasswordsController and change its redirect_to, but no success. In fact, I don't think Rails is even taking in my class. It could be a very stupid mistake but I have been at it for half a day with no success.

I took the idea to override the passwords controller from here.

Here's my controller:

class PasswordsController < Devise::PasswordsController
  protected
  def after_sending_reset_password_instructions_path_for(resource_name)
    root_url
  end
end

Routes.rb:

devise_for :users, :controllers => {:passwords => "passwords"}
devise_for :users, :controllers => {:registrations => "registrations"}
devise_for :users, :controllers => {:sessions => "sessions"}

I would like to mention that I have overridden Devise's Registations and Sessions Controllers in the same app, and they seem to work fine.

1

2 Answers 2

12

It should be possible to override the controller with the latest version of Devise (2.1.2).

class PasswordsController < Devise::PasswordsController
  def new
    super
  end

  def create
    ..override method here..
  end
end

And in config/routes.rb:

devise_for :users, controllers: { passwords: 'passwords', .. }

You can check with rake routes if Rails uses the derived PasswordsController instead of the original one, the routes should for instance contain passwords#new instead of devise/passwords#new.

3

I think you forgot to mention your changes in the routes:

devise_for :users, :controllers => {:sessions => "sessions", :passwords => "passwords"}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.