I am trying to fire a form submit using UJS:
<%= f.file_field :profile_image,
direct_upload: true,
accept: 'image/png,image/gif,image/jpeg',
onchange: "Rails.fire(this.form, 'submit')"
%>
However, I see the following error in the JS console:
ReferenceError: Can't find variable: Rails
The application layout file points to the application JS pack:
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
And I can see that it loads by the output of console log:
console.log('Application pack loaded')
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("@rails/activestorage").start()
From what I understand, rails ujs should expose the Rails
object. Is that right?
Why isn't the Rails
variable available to the browser? What do I need to do to ensure it is?