Rails 7: The Missing Instructions

Sadly, I had a lot of difficulty getting Rails 7 with Turbo and Stimulus up and running. The Rails docs feel like they’re missing a few steps, so I wanted to document the commands I needed to run to get Rails 7 with the hotwire.dev tooling up and running.

First, create the directory for your Rails app and add an empty Gemfile:

mkdir rails_app
cd rails_app/
touch Gemfile

Edit the Gemfile created above in your editor of choice and add the following content:

# Gemfile

source "https://rubygems.org"
gem "rails", "7.0.4"

Then run the following commands in the root of your Rails app:

gem install bundler

gem install rails

bundle exec rails new . \
  --css=sass \
  --javascript=importmap \
  --database=postgresql \

# n-install (see http://git.io/n-install-repo)
curl -L https://bit.ly/n-install | bash

# Install NPM dependencies
npm install --global esbuild sass

# Install yarn
# Note: Yarn > 1.x is NOT currently supported
npm install --global yarn

# Add hotwire.dev to NPM
yarn add @hotwired/stimulus
yarn add @hotwired/turbo-rails

# Install hotwire.dev stuff
bundle add importmap-rails
bin/rails importmap:install
bundle add hotwire-rails
bin/rails hotwire:install

# Run the app as follows
# (no more bundle exec rails server)
./bin/rails server

The following was pulled together from multiple sources, including but not limited to:

Hope that helps – happy coding!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.