0

I'm sending simple ajax call :

  axios({
    method: "post",
    url,
    headers: {
      "Content-Type": "application/javascript",
      "X-CSRF-Token": headerToken()
    }
  })

to the following action :

def search
  @products = ::Product.search(params[:keyword])
end

the .js.erb template get correctly returned, however the javascript contained in it does not get parsed, rather rendered as plain text

Tried the following :

form = document.querySelector('form');
Rails.fire(form, 'submit');

Same result.

What setup is missing here ?

Ben
  • 5,030
  • 6
  • 53
  • 94

1 Answers1

0

The answer is here.

window.Rails is undefined, so it has to be imported in the files where it is used.

Then :

form = document.querySelector('form');
Rails.fire(form, 'submit');

Works as expected

Ben
  • 5,030
  • 6
  • 53
  • 94