Rails Devise: Redirect user to current page after signing in
<p>If I access <a href="http://example.com" rel="nofollow noreferrer">http://example.com</a>, I am first taken to the login page and after successful login, to the home page.
If I access <a href="http://example.com/myusers" rel="nofollow noreferrer">http://example.com/myusers</a>, after successful login, I want to be redirected to the current page and not the home page.</p>
<p>After reading a few online posts, I understood that in my application_controller.rb I can manipulate the after_sign_in_path_for method. I tested this by adding a specific url to this method and I always get redirected to that url after a successful login.</p>
<pre><code>def after_sign_in_path_for(resource)
     &quot;http://example.com/users&quot;    
end
</code></pre>
<p>How can I make this method capture the URL that the user requested before signing in and redirect the user accordingly?</p>