Using request.referer to redirect

I have two edit pages in my application. After the changes have been saved, I want to redirect the user to another page depending on whether they are on the "/ info" or "/ edit" page. I am trying to use request.referer to find the path the user has come to decide where to redirect him.

(If they are in '/ info', they came from '/ users / sign_up')

controller

if URI(request.referer).path == '/users/sign_up'
  redirect_to root_path, notice: "Welcome" 
else 
 redirect_to user_path(@user)
 end

The problem is that it redirects to user_path no matter where the user is located.

(BTW, I am not configured to use request.referer to solve this problem. I also tried to use 'current_uri = request.env [' PATH_INFO ']' with the same luck)

+4
source share
1 answer

When you are in / info and then making changes, you go to a separate action and another page (edit page). Thus, the referee will be an information page, not a page. Try:

if URI(request.referer).path == '/info'
  redirect_to root_path, notice: "Welcome" 
else 
 redirect_to user_path(@user)
 end
+3
source

All Articles