Getting session authenticity token via ajax (rails, jquery)

Posted by ming yeow on Stack Overflow See other posts from Stack Overflow or by ming yeow
Published on 2010-06-07T03:45:00Z Indexed on 2010/06/07 3:52 UTC
Read the original article Hit count: 417

Hi folks, I wish to authenticate a user without having the page reloaded, and having the user submit a given form.

However, the problem that I immediately run into here is that the authenticity token typically gets set when the page is reloaded.

I need the authenticity token for the form submission, but i do not have it yet because the page is yet to reload.

I figure this cannot be that rare - anyone has any idea on how to resolve this?

1 idea could be getting rails to pass back the authenticity token after authentication, but i do not know how to access it from the controller

1) not logined user sees form

2) not logined user types in message and submit

3) facebox asking for authentication

4) after authentication, submit form automatically without refreshing

5) //but authenticity token is needed for form submission, which is not there yet

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about ruby-on-rails