title: Redirect loop with Devise after_sign_in_path_for
body: <p>I'm having a bit of a noob issue. I wanted to get devise to redirect to the last page the user visited. So I did the following...</p>
  
  <pre><code>def after_sign_in_path_for(resource)
      request.referer
  end
  </code></pre>
  
  <p>Works great...except if the user is actually logging in through the original form which causes a redirect loop. </p>
  
  <p>I tried </p>
  
  <pre><code>def after_sign_in_path_for(resource)
     if (request.referer == "/users/sign_in")
    :pages_home
   else
    request.referer
   end
  
  end
  </code></pre>
  
  <p>But thats not working, most likely because I have no idea what request.referer is actually returning when it encounters the original user login page (www.example.com/users/sign_in).</p>
  
  <p>Any ideas?</p>
  
  <p>tldr; Using devise, I want to redirect to the page logged in from (i.e /blog/4) unless the page is /users/sign_in</p>
  
  <p><strong>SOLVED:</strong></p>
  
  <p>Matchu was right. The request.referer was returning the domain as well...</p>
  
  <pre><code>http://example.com/users/sign_in
  </code></pre>
  
  <p>(note: no www prefix)</p>
  
  <p>I'm still interested in an alternative to request.referer if its an insecure or inefficient way.</p>