You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
After masquerading, return to page I started masquerading from #148
I click the masquerade button on the admin_user_path(:id) (e.g. https://example.com/admin/users/10122496). When I stop masquerading, I'd like to return to that same page.
I thought Devise.masquerade_routes_back = true would do it but that seems to try to take you to that page when you start masquerading, not when stopping
I tried overriding after_back_masquerade_path_for(resource) (code below) but it seems to be too late to grab the masqueraded user. Both resource and current_user refer to (what was) the masquerading_current_user
I hoped maybe I could use *opts with back_masquerade_path(current_user) but I'm not sure where to start
class Admin::MasqueradesController < Devise::MasqueradesController
protected
def after_back_masquerade_path_for(user)
# `user` and `current_user` are both the masquerading user, not the masqueraded user
admin_user_path(user.id)
end
end
I have found the solution you have to make the Devise.masquerade_routes_back = false in devise initialize and now if you add the
class Admin::MasqueradesController < Devise::MasqueradesController
protected
def after_back_masquerade_path_for(user)
# `user` and `current_user` are both the masquerading user, not the masqueraded user
admin_user_path(user.id)
end
end
Activity
o2h-vipul commentedon May 29, 2025
Same is happening with me. Thanks for pointing out @matt17r
o2h-vipul commentedon May 29, 2025
I have found the solution you have to make the
Devise.masquerade_routes_back = falsein devise initialize and now if you add thethat would work.
I hope this will help.