This Stimulus application will show how to install Stimulus into a Rails 7 application implementation with importmap-rails
. It will also show an example of an accordion used in modern applications.
This app was generated as a minimal install using:
$ rails new stimulus-example --minimal
If you are downloading this to run locally clone the repository from here
$ git clone https://github.com/leesheppard/stimulus-example.git
$ cd stimulus-example
$ bundle
Add importmap-rails to the Rails application:
$ ./bin/bundle add importmap-rails
$ ./bin/rails importmap:install
Rails generates:
Use vendor/javascript for downloaded pins
create vendor/javascript
create vendor/javascript/.keep
Ensure JavaScript files are in the Sprocket manifest
append app/assets/config/manifest.js
Configure importmap paths in config/importmap.rb
create config/importmap.rb
Copying binstub
create bin/importmap
Add stimulus-rails to the Rails application:
$ ./bin/bundle add stimulus-rails
Install stimulus
$ ./bin/rails stimulus:install
Generate a new stimulus controller with:
$ rails g stimulus toggle
Rails generates:
create app/javascript/controllers/toggle_controller.js
Generate a Home page:
$ rails g controller Home index
Rails generates:
create app/controllers/home_controller.rb
route get 'home/index'
invoke erb
create app/views/home
create app/views/home/index.html.erb
invoke test_unit
create test/controllers/home_controller_test.rb
invoke helper
create app/helpers/home_helper.rb
invoke test_unit