Redirect To Current Page After Login | GoRails - GoRails
For those who want similar behaviour on before_action :authenticate_user!
def authenticate_user!(opts = {})
unless opts || user_signed_in? || devise_controller? || !redirectable?
store_location_for(:user, request.fullpath)
end
super(opts)
end
def redirectable?
request.get? && !request.xhr? && is_navigational_format?
end
FYI in the after_sign_in_path_for(resource) method I had to change
new_session_url
to Devise's:
new_user_session_url
How do I achieve this redirect for any page and all links, rather than just on the 'Login' page? That's the major downside I see to this approach. I would have to setup a parameter for every link, right?
This doesn't make sense for a site that's globally locked down. That's why it's designed in the way that it is.
If you're locking down everything, the Devise before_action :authenticate_user!
can take care of that for you. You can also put that in ApplicationController to have it apply to every single request.
Why not a simple cookie with current_path (set on every page), after sign_up or sign_in you simply get the cookie and redirect to it.
You don't necessarily always want to redirect to that same page, this way you can specify it as you want. Of course, you can set it up that way to always set a cookie. Depends on what you're looking to accomplish really.
@disqus_HFIU4QcJxV:disqus this would lead to issues if a user were to 'right-click + open' multiple pages in different browser tabs, the cookie would keep getting overwritten and would likely lead to unexpected results
Hey Chris, are there any open source online code editors similar to Codepen I can integrate into my rails app and build upon it to work with my site dynamically.
There are, although I haven't personally used any so I can't confirm if they're any good. You can check out like https://www.nitrous.io/ and https://c9.io/