1

I am updated a Rails 6 app to Rails 7 and using importmaps and Leaflet. I am following How do I use Leaflet in Rails 7?. I successfully build a new app and it works fine, but upgrading my old app does not.

What am I missing? Or what debugging steps to try?

No errors in Terminal running server and no Console errors in Chrome. However in the new app following the answer, I see

Chrome dev mode sources. But in the updated app,

Upgraded app sources

Looks to me like the controllers are not getting loaded.

// app/javascript/application.js
import "@hotwired/turbo-rails"
import "controllers"
import "popper"
import "bootstrap"

# config/importmaps.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 "jquery", to: "https://ga.jspm.io/npm:jquery@3.6.1/dist/jquery.js", preload: true
pin "popper", to: 'popper.js', preload: true
pin "bootstrap", to: 'bootstrap.min.js', preload: true
pin "leaflet", to: "https://ga.jspm.io/npm:leaflet@1.9.0/dist/leaflet-src.js", preload: true
pin "leaflet-css", to: "https://ga.jspm.io/npm:leaflet-css@0.1.0/dist/leaflet.css.min.js", preload: true
pin "leaflet.control.opacity", to: "https://ga.jspm.io/npm:leaflet.control.opacity@1.6.0/dist/L.Control.Opacity.js", preload: true
pin "leaflet.timeline", to: "https://ga.jspm.io/npm:leaflet.timeline@1.4.3/dist/index.js", preload: true

// Gemfile
ruby '3.1.2' 
gem 'rails', '~> 7.0'
gem 'pg' , '~> 1.4.3'
gem "net-http" 
gem 'puma'
gem 'sassc-rails'
gem "importmap-rails", "~> 1.1"
gem "turbo-rails"
gem "stimulus-rails"
gem "sprockets-rails"
gem 'bootsnap', require: false
gem 'bootstrap', '~> 5.0.0'

// app/javascript/controllers/index.js
import { application } from "controllers/application"
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
eagerLoadControllersFrom("controllers", application)

// app/javascript/application.js
import "@hotwired/turbo-rails"
import "controllers"
import "popper"
import "bootstrap"
Greg
  • 2,359
  • 5
  • 22
  • 35

1 Answers1

2

Let me guess, you didn't update manifest.js. You should have app/javascript there:

// app/assets/config/manifest.js

//= link_tree ../images
//= link_directory ../stylesheets .css
//= link_tree ../../javascript .js
//  ^ this one
//= link_tree ../../../vendor/javascript .js
Alex
  • 16,409
  • 6
  • 40
  • 56
  • @Greg try running `bin/importmap json` it should print all the imports. check for typos, it should be singular `config/importmap.rb`. – Alex Oct 14 '22 at 15:39
  • Thank you. That's helpful. The Stimulus controllers are loading now. I'm not quite sure where the change was that did it. – Greg Oct 16 '22 at 05:43