# Login Redirect - Hacking the session\[original\_uri\]

**URL:** <https://www.ruby-forum.com/t/login-redirect-hacking-the-session-original-uri/119018>\
**Category:** Rails\
**Created:** [November 2, 2007, 7:19am UTC](https://www.ruby-forum.com/t/login-redirect-hacking-the-session-original-uri/119018 "2007-11-02T07:19:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgiorno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mgiorno](https://www.ruby-forum.com/u/mgiorno)\
**Post date:** [November 2, 2007, 7:19am UTC](https://www.ruby-forum.com/t/login-redirect-hacking-the-session-original-uri/119018/1 "2007-11-02T07:19:03Z")

</div>

Hi There,

I have several ajax elements that require authorization, but for various  
reasons, they can’t pass session[original\_uri] to the redirect on user  
log in. I’m trying to hack in a uri by passing a param to the login  
page.

I can see that the param is passing into the login page, but for  
whatever reason, no matter what I do, the user is redirected to the  
homepage after login.

Would anyone have any ideas? thanks soo much!

-Mario

#code from show.rhtml  
if current\_user  
#ajax code  
else  
link\_to “vote up”, login\_url(:referrer\_uri =\> request.request\_uri) %\>  
end

#Controller  
def create

```
uri ||= params[:referrer_uri] #pull in hacked original_uri
uri ||= session[:original_uri] #pull in sessions's original uri
uri ||= homepage_url #default to homepage

render :action => :new and return true if request.get?

if params[:user_name] and params[:password] and user =

```

User.authenticate(params[:user\_name], params[:password])  
session[:user\_id] = user.id  
session[:original\_uri] = nil  
redirect\_to(uri) and return true  
else  
flash[:failure] = “Invalid username or password.”  
redirect\_to login\_url and return false  
end  
end

---

<div class="post-metadata">

**Author:** ![mgiorno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mgiorno](https://www.ruby-forum.com/u/mgiorno)\
**Post date:** [November 14, 2007, 3:02am UTC](https://www.ruby-forum.com/t/login-redirect-hacking-the-session-original-uri/119018/2 "2007-11-14T03:02:39Z")

</div>

No Luck, hu?

---

<div class="post-metadata">

**Author:** ![mgiorno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mgiorno](https://www.ruby-forum.com/u/mgiorno)\
**Post date:** [November 14, 2007, 10:53am UTC](https://www.ruby-forum.com/t/login-redirect-hacking-the-session-original-uri/119018/3 "2007-11-14T10:53:19Z")

</div>

i’ve used that thing several times, as you want it and it works fine.

seems to me, it didn’t reach the redirect\_to(uri) line for some reason  
or uri is not set to the right path in the first lines of your action

check it that way:

add  
logger.info “URI: #{uri}”  
behind those “uri ||=” lines  
and something the like before your redirects. then check in  
development.log, what actually is in those vars and which parts of your  
code are reached.

---

<div class="post-metadata">

**Author:** ![mgiorno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mgiorno](https://www.ruby-forum.com/u/mgiorno)\
**Post date:** [November 14, 2007, 5:04pm UTC](https://www.ruby-forum.com/t/login-redirect-hacking-the-session-original-uri/119018/4 "2007-11-14T17:04:28Z")

</div>

Thanks for the tip!

That helped me track down my problem. Apparently, the uri wasn’t  
getting carried over the the create action in my session controller. So  
I just added the param to my login form.

\<% form\_tag login\_path(:referrer\_uri =\> params[:referrer\_uri]), :class  
=\> “submit-form login” do %\>

---

<div class="post-metadata">

**Author:** ![mgiorno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mgiorno](https://www.ruby-forum.com/u/mgiorno)\
**Post date:** [November 14, 2007, 5:10pm UTC](https://www.ruby-forum.com/t/login-redirect-hacking-the-session-original-uri/119018/5 "2007-11-14T17:10:18Z")

</div>

Mario F. wrote:

> Thanks for the tip!
> 
> That helped me track down my problem. Apparently, the uri wasn’t  
> getting carried over the the create action in my session controller. So  
> I just added the param to my login form.
> 
> \<% form\_tag login\_path(:referrer\_uri =\> params[:referrer\_uri]), :class  
> =\> “submit-form login” do %\>

lo, you didn’t mention a form, in that case te user had to press the  
‘submit’ and your link\_to is dead anyway (? i think) 🙂

your solution is ok, alternately you could pass stuff like that in a  
hidden field  
not, that there’s a big difference
