Stimulus Discourse

Rails/ujs import

Stimulus controller handles submitting form via rails ujs. The problem is rails ujs module does not load and it fails with Uncaught ReferenceError: Rails is not defined


import { Controller } from "stimulus"
import Rails from "@rails/ujs"

export default class extends Controller {
  static targets = [ "form" ]
  update() {, 'submit')



Any ideas on what could be the issue? I throw away a few hours of research and couldn’t figure out why Rails is not defined. I followed this post

Need expose the Rails in JS world, something like below commit.

Thank you.
I gave up and used stimulus-remote
I will try your solution.