0

If unauthenticated users attempt to access users/edit , devise redirects them to users/sign_in. This is good. However, after successful signing in, I wish the user to be redirected back to users/edit. How is this possible.

2 Answers 2

1

Have you overriden the after_sign_in_path_for method? Check out the wiki about How To: redirect to a specific page on successful sign in

Anyway, AFAIK, if you haven't overriden this method, the default behaviour is redirect user to the last stored location, 'users/edit' in that case. Check out the content of stored_location_for on your application before user is signed in.

1
  • Yes... I was overriding after_sign_in_path. By saving previous path in user_return_to I didn't have to override it anymore, and everything works fine now. Also I've now learned that I could have used stored_location_for(resource) in the overridden method and it would have worked.
    – Zuhaib Ali
    Mar 16, 2014 at 14:33
1

I interpret the question as how do I redirect back after sign in, where the answer would be thus:

https://github.com/plataformatec/devise/wiki/How-To:-redirect-to-a-specific-page-on-successful-sign-in

class ApplicationController < ActionController::Base
  def after_sign_in_path_for(resource)
    request.env['omniauth.origin'] || stored_location_for(resource) || root_path
  end
end

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.