# Acts\_as\_authenticated redirect on ajax requests

**URL:** <https://www.ruby-forum.com/t/acts-as-authenticated-redirect-on-ajax-requests/114323>\
**Category:** Rails\
**Created:** [September 11, 2007, 11:50am UTC](https://www.ruby-forum.com/t/acts-as-authenticated-redirect-on-ajax-requests/114323 "2007-09-11T11:50:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7cd45c/32.png) [@rene](https://www.ruby-forum.com/u/rene)\
**Post date:** [September 11, 2007, 11:50am UTC](https://www.ruby-forum.com/t/acts-as-authenticated-redirect-on-ajax-requests/114323/1 "2007-09-11T11:50:05Z")

</div>

Hi there,

I’d like to know if there is a solution to the scenario when using  
acts\_as\_authenticated and ajax:

I have an action in my controller which is protected by login via  
acts\_as\_authenticated. Now, this action can be called both by human  
interaction, as well as ajax requests. (It is an add to cart link). It  
works great as long as I am in an authenticated session.

Now, I want to display this add to cart link regardless if I am logged  
in or not (very important).  
When I switch off Javascript, I get redirected nicely to the login  
form when I click it.

With Javascript on, and thus ajax working, the ajax requests gets  
redirected to the login form (which I can see in the server log), but  
obviously the human is never shown a login screen - for him, nothing  
at all happens.

Is it possible to redirect the “page” if the ajax requests is  
redirected, so the login form is shown and the user is able to  
proceed?

What would be a better solution, if that’s not possible…I am kinda  
out of ideas.

Thanks for your help,  
Rene

---

<div class="post-metadata">

**Author:** ![rene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7cd45c/32.png) [@rene](https://www.ruby-forum.com/u/rene)\
**Post date:** [September 11, 2007, 12:06pm UTC](https://www.ruby-forum.com/t/acts-as-authenticated-redirect-on-ajax-requests/114323/2 "2007-09-11T12:06:12Z")

</div>

Oh, and I forgot to say…using a page.redirect in the RJS for the  
“add to cart” action does not work as this action is never hit because  
it is protected with the before\_filter :login\_required of  
acts\_as\_authenticated…

---

<div class="post-metadata">

**Author:** ![rene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7cd45c/32.png) [@rene](https://www.ruby-forum.com/u/rene)\
**Post date:** [September 11, 2007, 12:34pm UTC](https://www.ruby-forum.com/t/acts-as-authenticated-redirect-on-ajax-requests/114323/3 "2007-09-11T12:34:17Z")

</div>

Google was good to me today, here is the solution for the  
acts\_as\_authenticated method:

[http://projects.wh.techno-weenie.net/changesets/2203](http://projects.wh.techno-weenie.net/changesets/2203)

Now, it says I can overwrite the access\_denied method in the  
controller, but that doesn’t seem to work.

Anyway, I’ll edit the original.
