0

I am using devise for user registrations. I set up a custom edit page '/info' to use as an additional signup page. The only problem is after you submit the edits on the info page it redirects to the user profile. I am able to change it redirect to the home page (where I want after /info) but then it also redirects there from the normal edit page. I am not sure how to redirect based on what page the user is on.

My one idea was to get the users current path and use an if statement but I haven't been able to get that to work.

registrations_controller.rb:

 def update
 ...
 current_uri = request.env['PATH_INFO']

 if current_uri == '/info'
  redirect_to root_path, notice: "Welcome" 
 else 
  redirect_to user_path(@user)
 end

 end

Normally it just looks like this:

 def update 
 ...
 redirect_to user_path(@user)
 end
user2759575
  • 553
  • 3
  • 25

1 Answers1

0

The problem seems to be you need to keep data around to determine where to redirect. A few ideas:

  1. You could store data in the session when a user visits a previous page and check this data in your action to determine where to redirect the user. The session is often a convenient place to store things that are consistent between requests but that should not be persisted to the database.
  2. You could store data in the database (for instance, add a flag to your user model) and check this to determine where to redirect.
  3. You could check request.referer and redirect based on the value there. This may not be as reliable.
Puhlze
  • 2,634
  • 18
  • 16
  • I went with your last suggestion but I can't seem to get it to work. In the controller I have 'if URI(request.referer).path == '/users/sign_up' ' but that seems to have no affect. Weird since I pretty much took it straight from here (http://stackoverflow.com/questions/5819721/how-to-get-request-referrer-path) – user2759575 Aug 28 '14 at 03:16
  • Can you verify what URI(request.referer).path is? Maybe the string isn't what you're expecting. – Puhlze Aug 28 '14 at 13:39
  • Hmm, yeah in the view <%= URI(request.referer).path %> gives me a 'bad argument (expected URI object or URI string)' error. – user2759575 Aug 28 '14 at 17:10