@shankard, the best way to handle this is to use Rails’ form_authenticity_token helper to insert a hidden input into your form, and then include an authenticity_token field in your form submission.
You can also embed a CSRF token in your form with this tag in your tag:
Then modify your jQuery above to include authenticity_token in your form. Note that the authenticity token should be part of data, and not a child of content. (If you inspect the params hash for a standard Rails form submission, the token is not part of the submitted record, it’s a top-level parameter).
Would you mind checking that this line is in your app/assets/javascripts/application.js?
//= require jquery_ujs
Basically, that file will set jQuery’s AJAX default to automatically include the authenticity token, so you don’t have to do it yourself.
Also, I notice that you are trying to construct the content of the request there. Do you think you can actually grouped that up into a form? There’s an awesome helper .serialize() from jQuery that should serialize the form for AJAX request for you.
@sikachu thanks for your reply. I just learned about what jqueryujs does after reading your post. Infact my application included jqueryujs but I had added a few other js after that line (timelinejs and its stuff) which seemed to have broken this. I disabled these libraries and I was able to it working.
I’m not using forms for editing the content, rather using contenteditable for it. So I cannot use serialize here.