Live Reloading in Rails

aldoportillo

Aldo Portillo

Posted on November 1, 2023

Live Reloading in Rails

Introduction

When developing the frontend of any application, the most tedious thing is refreshing the client/server. Luckily, when it came to HTML, I had live server; and when it came to Node, I had Nodemon. When it came to ruby, the server refreshed but not the client.

Rails Live Reload

Is a Rails live reloader for views, partials, css, and js. This means that every single time you save a .erb, .css or .js file, the page will reload to show the changes.

Configuration

  1. In Gemfile add:
group :development do
  gem "rails_live_reload"
end
Enter fullscreen mode Exit fullscreen mode

In order to only download this gem in development. Then run bundle.

  1. Create Initializer
#Create config/initializers/rails_live_reload.rb and add
RailsLiveReload.configure do |config|
  # config.url = "/rails/live/reload"

  # Default watched folders & files
  # config.watch %r{app/views/.+\.(erb|haml|slim)$}
  # config.watch %r{(app|vendor)/(assets|javascript)/\w+/(.+\.(css|js|html|png|jpg|ts|jsx)).*}, reload: :always

  # More examples:
  # config.watch %r{app/helpers/.+\.rb}, reload: :always
  # config.watch %r{config/locales/.+\.yml}, reload: :always

  # config.enabled = Rails.env.development?
end if defined?(RailsLiveReload)
Enter fullscreen mode Exit fullscreen mode
  1. Enjoy! With just two steps you saved yourself hours of refreshing the client in Rails!
💖 💪 🙅 🚩
aldoportillo
Aldo Portillo

Posted on November 1, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related