简体   繁体   中英

request.url is giving me example.com/login instead of example.com/feed

Rails 4.2.2

If I click on the link:

<%= link_to "Feed", feed_path, data: {turbolinks: false } %>

or paste the url

www.example.com/feed

A before_action in my UsersController redirects to the login_url

Application Controlller
def logged_in_user
  unless logged_in?
    store_location
    flash[:danger] = "Please log in."
    redirect_to login_url
  end
end

module SessionsHelper
def store_location
  session[:forwarding_url] = request.url if request.get?
end

def redirect_or
  redirect_to(session[:forwarding_url] || root_url)
  session.delete(:forwarding_url)
end

After successfully logging in, the redirect_or method is redirecting me back to the login_url.

request.url is being saved as www.example.com/login

You didn't add store_location to the login_url after this comment did you?

If you did you are overwriting store_location with the login_url after the redirect_to login_url ... which you don't want to do.

If that is not the issue I would add puts in store_location before and after session[:forwarding_url] because I don't think it's getting saved properly.

Nice work debugging this one

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM