Oguz Bilgic
Oguz Bilgic

Reputation: 3480

Render js.erb for XHR request

I want to set rails to render .js.erb files by default for xhr requests.

Upvotes: 2

Views: 822

Answers (1)

Heikki
Heikki

Reputation: 15417

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

Upvotes: 2

Related Questions