All threads / Redirect To Current Page After Login | GoRails - GoRails
Ask A Question


You’re not receiving notifications from this thread.

Redirect To Current Page After Login | GoRails - GoRails

Chris Oliver asked in General

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)

def redirectable?
request.get? && !request.xhr? && is_navigational_format?

FYI in the after_sign_in_path_for(resource) method I had to change
to Devise's:

Jordano Moscoso ·

Thanks, i was wondering what was going on.

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

Manuel Quintanilla ·

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 and

Manuel Quintanilla ·

I've found built with c/c++ most likely. We won't necessarily be running the editor in our rails app, however we need to pull information from it. So would I need to build a ruby extension to retrieve information from the C/C++ application like user information? Trying to wrap my head around it...

Normally you would just make HTTP requests to something like this if it has an API. It doesn't look like this has one, and it's probably not written in C because that's just too much work for building a website generally. This is probably mostly JS and some server side language like PHP, Ruby, or Python.

Manuel Quintanilla ·


It can be used to devise the latest version of 4.1.1?

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 70,078+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.