Development 2022-10-17

HotReload with Ruby On Rails 7

Grzegorz Smajdor

Grzegorz Smajdor

Software Engineer & CTO

At deliverists.io we build custom software and deliver quality products to our clients. Some time ago, we worked on a project with ClojureScript.

There are many benefits to this language, but today I want to focus on the feature called hot-reload. The idea is super simple, yet powerful: the web page is reloaded on file save. This small but useful feature saved me a few keystrokes and allowed me to stay focused in the editor while seeing immediate changes in the browser.

As you can see above, without moving out from my editor, the page reloads and I can see the changes immediately! Now… let's replicate that behavior in Ruby on Rails 7.


Let's quickly build a new Ruby on Rails app

gem install rails
rails new test-app --css tailwind
cd test-app
./bin/dev

Then we need to do a few configuration changes:

  1. Edit Gemfile and add hotwire-livereload gem:

    group :development do
      gem "hotwire-livereload"
    end
    
  2. Install with bundler

    bundle install
    
  3. Run installation

    rails livereload:install
    
  4. Install Redis (macOS with Homebrew)

    brew install redis
    
  5. Run Redis

    brew services restart redis
    
  6. Run Rails

    ./bin/dev
    

Edit the file and see the changes!

No more switching windows, hitting F5! That's a live and time saver.


Have fun and keep coding,

Grzegorz, founder of deliverists.io