Rails 6.0, Webpack and Stimulus.js on Raspberry Pi
Follow my previous article on Rails 5, this one describes the setup of Rails 6.
After installation of Rails 6, simply create a new application like this:
$ rails new new_app --database=postgresql
It will install almost everything, including gems and webpack. It will take a while on Raspberry Pi.
Create the database after editing config/database.yml
based on your development setup by bundle exec rake db:create
, followed by bundle exec rake db:migrate .
You can start Rails with bundle exec rails server -b 0.0.0.0
. My development machine is in private network, thus, I can check the result at http://192.168.10.64:3000.
Let’s try install stimulus.js this time by
bundle exec rails webpacker:install:stimulus
Then create a home page with this:
bundle exec rails g controller pages home
Edit app/view/pages/home.html.erb:
<div data-controller="hello">
<h1 data-target="hello.output"></h1>
</div>
There is a corresponding javascript controller at app/javascript/controllers/hello_controller.js
Start the server and go to /pages/home.html and “Hello, Stimulus!” should show up.