0

I am trying to upgrade a project from Rails 6 to Rails 7.

Gemfile

ruby '3.1.2'
gem 'rails',           '7.0.4'
gem "sassc-rails",     '2.1.2'
gem "sprockets-rails", "3.4.2"
gem "importmap-rails", "1.1.0"
gem "turbo-rails",     "1.1.1"
gem "stimulus-rails",  "1.0.4"
gem "jbuilder",        "2.11.5"
gem "puma",            "5.6.4"
gem "bootsnap",        "1.12.0", require: false
gem 'sass-rails',      '6.0.0'

app/assets/config/manifest.js

// link_directory ../javascripts .js
//= link_tree ../images
//= link_directory ../stylesheets .css
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js

config/importmap.rb

pin "application", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin_all_from "app/javascript/controllers", under: "controllers"
pin_all_from "app/javascript/custom",      under: "custom"

app/javascript/application.js

import "@hotwired/turbo-rails"
import "controllers"
import "custom/menu"
alert('hello');

I have moved all my javascript files from app/assets/javascripts/ to app/javascript/, and deleted the old application.js in assets.

The javascript in app/javascript/application.js should be loaded, which means an alert box with "hello" in should appear, but it does not. Where am I going wrong?

3
  • you're probably loading app/assets/javascripts/application.js instead of app/javascript/application.js. you need to remove the old application.js or rename it if you still need it. Commented Aug 9, 2024 at 22:43
  • I have deleted the old application.js but the behaviour is the same. Question updated. Commented Aug 10, 2024 at 20:21
  • do you have <%= javascript_importmap_tags %> in your layout? Commented Aug 10, 2024 at 20:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.