Getting error “Library not loaded: libmysqlclient.18.dylib (LoadError)” on Mac running rake task as cronjobs – rvm
Rails session lost when calling request via jquery/ajax
On January 8, 2012,
in IT Related, Ruby on Rails,
by admin
Before calling the ajax request, add this:
$.ajaxSetup({
‘beforeSend’: function(xhr) { xhr.setRequestHeader(‘X-CSRF-Token’, $(“meta[name='csrf-token']“).attr(‘content’)); }
});
then you can all the ajax reqeust after that:
$.ajax({
type: “POST”,
url: “/your-url-here”,
data: $(form).serializeArray()
});
Make sure to add this in your view template:
<%= csrf_meta_tag %>
And add this javascript :
https://github.com/rails/jquery-ujs
https://github.com/rails/jquery-ujs
Enjoy!
