Skip to content

Rails needs xhr.setRequestHeader("Accept", "text/javascript"); #52

@gygelly

Description

@gygelly

So I made a form the rails way, with:
form_tag, :remote=>true`

The controller it submitted to had the standard:

respond_to do |format|
    format.html 
    format.js
end

When I submitted the form, it did submit as an xhr request, but rails responded by rendering the .html.erb instead of the .js.rjs

This is because the Request Header: Accept is set to / (discovered via Chrome's resources tab).

To fix this, I had to edit your rails.js at line 56-59 the following way:

beforeSend: function (xhr) {
  xhr.setRequestHeader("Accept", "text/javascript");
  el.trigger('ajax:loading', xhr);
},

I'm not submitting this as a patch, as I suspect this needs to be added in other places, but I'm not nearly smart enough to know where.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions