1

I am using devise gem version 4.1.1 in my rails project and in my /users/edit page I want to redirect to the same page after the user changes his password instead of redirecting to the root_path. I googled around and found this link devise github wiki

I did make the changes accordingly and my registrations controller is as follows

class RegistrationsController < Devise::RegistrationsController

  protected

  def after_update_path_for(resource)
    edit_user_registration_path
  end
end

and in routes.rb I added the registrations controller

devise_for :users, controllers: { confirmations: "confirmations", registrations: "registrations"}

But still for some reason I am not able to redirect to the same page and it still redirects to root_path. Am I missing something?

EDIT 1: I am also using backbone-rails gem to use backbone.js inside my rails app. The router class of backbone.js is as follows

class Pulse.Routers.MainRouter extends Backbone.Router
 routes:
  "new"                                       : "newBranch"
  ""                                          : "analytics"
  "analytics"                                 : "analytics"
  "voices"                                    : "manageVoice"
  "branches"                                  : "manageBranch"
  "tablets"                                   : "manageTablet"
  "branch/:branchId/tablet/:tabletId/edit"    : "tabletEdit"
  "branch/:branchId/tablet/new"               : "tabletAdd"
  "timeline"                                  : "timeline"
  "reports"                                   : "reports"
  "questions"                                 : "manageQuestion"
  "users"                                     : "users"
  ":id/edit"                                  : "edit"
  ":id"                                       : "show"
  ".*"                                        : "index"

followed by the corresponding functions that renders the views and my routes.rb for the user is as follows

authenticated :user do
  root 'static_pages#home', as: :authenticated_root
end
root 'static_pages#landing' 

Whenever I update the profile of the user I can see the browser address as "/users/edit" but the index page is getting displayed which is due backbone.js router file. I can see that the control is going to the router file after I inserted a console.log statement there. So is there anyway that I can bypass the backbone router and display the '/users/edit' page after user updates his profile?

Nikhil Gopinath
  • 170
  • 1
  • 12
  • I know this is not exactly as you need, but you could simply pass a `redirect_to :back` in form's controller for create, edit or other action – Julius Dzidzevičius Dec 04 '16 at 16:02
  • The devise gem doesn't provide any form's controller as such.... It has the registrations_controller where i can provide the redirection path and that is exactly what i have done.... I can even see the correct url in the address bar in browser but for some reason the roor_path page is being loaded... – Nikhil Gopinath Dec 05 '16 at 07:26
  • Oh.... I haven't used the before_filter inside registrationscontroller.... How do i do that... Should i write before_filter and use the method reference inside it? – Nikhil Gopinath Dec 05 '16 at 08:57
  • And one interesting topic here - http://stackoverflow.com/questions/22063026/how-do-i-override-devise-controller-and-devise-routes-at-the-same-time – Julius Dzidzevičius Dec 05 '16 at 09:23
  • I have deleted my suggestions for `before_action`, since it is used just for DRY purposes... Sorry for a bad advice – Julius Dzidzevičius Dec 05 '16 at 10:16

0 Answers0