Render js.erb for XHR request
I want to set rails to render开发者_开发知识库 .js.erb files by default for xhr requests.
If you are using jQuery then update your rails.js to the latest from here https://github.com/rails/jquery-ujs and set the default request header for ajax calls with this:
$(function() {
jQuery.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader("Accept", "text/javascript");
}
});
});
Here is a very recent commit for reference: https://github.com/rails/jquery-ujs/commit/fbbefa0773d791d3a67b7a3bb971c10ca750131b
精彩评论