I'm not sure if this is an importmaps issue or something else, but in Rails 7.0.0.alpha2, I'm getting 404 errors on the javascript files.
Wondering if I'm missing some sort of production "compile" step as it works fine in development.
# app/javascript/application.js
import "@hotwired/turbo-rails"
import "controllers"
# app/javascript/controllers/index.js
import { application } from "./application"
import VoteController from "./vote_controller.js"
application.register("vote", VoteController)
# app/javascript/controllers/vote_controller.js
import { Controller } from "@hotwired/stimulus"
// Connects to data-controller="vote"
export default class extends Controller {
static targets = ["element"];
toggle(event) {
//event.preventDefault();
event.target.classList.add("opacity-100");
event.target.classList.remove("opacity-0");
}
}
# config/importmap.rb
pin "application", preload: true
pin "@hotwired/turbo-rails", to: "turbo.js"
pin "@hotwired/stimulus", to: "stimulus.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin_all_from "app/javascript/controllers", under: "controllers"
Then in my app/views/layouts/application.html.erb
file I'm using <%= javascript_importmap_tags %>
to include it all.
If I set config.assets.compile = true
in production.rb
, the errors go away...but I'm not sure why or if that's fixing the core issue.