# Escaping the AJAX View

**URL:** <https://www.ruby-forum.com/t/escaping-the-ajax-view/53818>\
**Category:** Rails\
**Created:** [February 14, 2006, 10:14pm UTC](https://www.ruby-forum.com/t/escaping-the-ajax-view/53818 "2006-02-14T22:14:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dylan\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Dylan\_S](https://www.ruby-forum.com/u/Dylan_S)\
**Post date:** [February 14, 2006, 10:14pm UTC](https://www.ruby-forum.com/t/escaping-the-ajax-view/53818/1 "2006-02-14T22:14:41Z")

</div>

I have a login form, in which I use a “form\_remote\_tag”.  
I’m redirecting users to this form when they fail authentication as  
well…  
and using the “jumpto” method of capturing they  
original URL they requested via request.parameters, and redirecting to  
this  
URL after they authenticate.

Problem is, if I try to do a “redirect\_to”, this won’t work, as I’m  
still in  
the AJAX request.

I’m assuming my only alternatives are:

1. Not use AJAX
2. Send un-authenicated users to a different non-ajaxed login form.
3. Parse the request.parameters, then pass the URL as a variable into a  
template which then does a window.location redirect.

Any other ideas ?

---

<div class="post-metadata">

**Author:** ![Dylan\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Dylan\_S](https://www.ruby-forum.com/u/Dylan_S)\
**Post date:** [February 17, 2006, 4:22am UTC](https://www.ruby-forum.com/t/escaping-the-ajax-view/53818/2 "2006-02-17T04:22:26Z")

</div>

^bump^

---

<div class="post-metadata">

**Author:** ![Dylan\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Dylan\_S](https://www.ruby-forum.com/u/Dylan_S)\
**Post date:** [February 17, 2006, 9:24am UTC](https://www.ruby-forum.com/t/escaping-the-ajax-view/53818/3 "2006-02-17T09:24:53Z")

</div>

You can use RJS to redirect the user. In the action you can do…

render :update do |page|  
page.redirect\_to :action =\> :my\_action  
end

-Jonny.

Dylan S. wrote:

> ^bump^

---

<div class="post-metadata">

**Author:** ![Dylan\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Dylan\_S](https://www.ruby-forum.com/u/Dylan_S)\
**Post date:** [February 17, 2006, 7:07pm UTC](https://www.ruby-forum.com/t/escaping-the-ajax-view/53818/4 "2006-02-17T19:07:10Z")

</div>

Genius, thanks Jonathan 🙂  
My fear of RJS templates has been vanquished ! Edge demons be gone !!

It took me literally 10 minutes to switch out a complex form over to  
RJS.  
It works perfectly now.

Thank you, thank you, thank you 🙂

---

<div class="post-metadata">

**Author:** ![Dylan\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Dylan\_S](https://www.ruby-forum.com/u/Dylan_S)\
**Post date:** [February 18, 2006, 1:46am UTC](https://www.ruby-forum.com/t/escaping-the-ajax-view/53818/5 "2006-02-18T01:46:36Z")

</div>

No problem. RJS is a very powerful tool.

-Jonny.

Dylan S. wrote:

> Thank you, thank you, thank you 🙂
