Password controller update method

752 views Asked by At

I am trying to implement a reset password page using Devise.

What I want to achieve is to redirect the page to a different route after the password is being updated. So, I made the change in my passwords_controller.rb based on the documentation.

My Controller looks like this:

class Users::PasswordsController < Devise::PasswordsController
  # basic is my html.erb file for layout purpose....
  layout "basic"

  def edit
    render :edit
  end

  def after_resetting_password_path_for(resource)
    root_path
  end
end

In my routes.rb file. I have included the route for password controller:

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

Here, I am able to access my view in app/views/passwords/edit.html.erb.

The problem is the after_resseting_password_path_for method (which is being overridden in passwords_controller.rb) which is not getting executed and I am redirected to the same page in my output instead of root_path. Also the update is not made.

Is it the problem with the update method implemented in Devise or I am missing something?

2

There are 2 answers

7
zeantsoi On

I suspect that – since you've overridden the default Devise PasswordsController – your edit action is looking to post to an update action in the same controller, but there is none. Try updating your custom controller to the following:

class Users::PasswordsController < Devise::PasswordsController

  layout "basic"

  def edit
    render :edit
  end

  def update
     render :update
  end

  def after_resetting_password_path_for(resource)
    root_path
  end    

end

Alternatively, I imagine that if you were to specify after_resetting_passwords_path in your ApplicationController, you'd be able to bypass overriding Devise::PasswordsController entirely (though you'd need to conditionally set your layout in the ApplicationController).

0
user On

this might be help..i use this and it work..just sharing.. http://www.stumbleupon.com/su/34E99D#