Acts_as_authenticated redirect on ajax requests

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

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…

Google was good to me today, here is the solution for the
acts_as_authenticated method:

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs