On 29 Jul 2008, at 01:00, Elliot Chyba wrote:
> I''m integrating Lightview,
> http://www.nickstakenburg.com/projects/lightview/, into an
> application.
> It''s more or less a content overlay similar to a light box, which
then
> calls the content either through an IFRAME or Ajax request. The IFRAME
> works fine but for obvious reasons, I''d prefer to use Ajax but
> whenever
> I use that option, I get the dreaded InvalidAuthenticityToken error.
>
> Do any ideas come to mind?
Add this in the <head> section of your main layout file:
<script type="text/javascript" charset="utf-8">
window._token = ''<%= form_authenticity_token
-%>'';
</script>
Add this on top of your /javascripts/application.js file:
Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap(
function(p, options){
p(options);
this.options.parameters = this.options.parameters || {};
this.options.parameters.authenticity_token = window._token ||
'''';
}
);
Presto! All ajax requests that are called from your own javascript
code will have the authenticity string added to the parameters.
Best regards
Peter De Berdt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---