Peter Laurens
2009-Nov-01 16:15 UTC
Ajax calls in application.js (authenticity_token problem?)
Hi, I have a long list (~50) of items which should each be clickable and will send an Ajax request to the server. Now, each item will be calling the same action, just with a different id. Ideally this looks like a clear case of putting the Ajax javascript in application.js. It''s in one place, just call a single function onclick and pass through the id. However there are 2 issues: 1. I am worried that the Ajax request from application.js will not have access to any authenticity token as it was not generated by a Rails helper, and this could cause problems? 2. I''d prefer to use the Rails helpers to write the remote request if possible, in application.js I have to resort to hand-coding javascript. The easy solution is just to have individual Ajax request code for each list item''s onclick call, but that would bulk out the file a fair bit and seems messy. So I''m between a rock and a hard place... Any advice much appreciated! -P -- Posted via http://www.ruby-forum.com/.