Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot override Devise passwords controller

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.

like image 832
abhijeetmisra Avatar asked Jan 10 '12 19:01

abhijeetmisra


1 Answers

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.

like image 128
0x4a6f4672 Avatar answered Sep 23 '22 19:09

0x4a6f4672