Live Reload

Live reloads rails assets using guard
Used 28 times
Created by
M Michael Yagudaev

Usage

Install the rails byte, then simply run

guard


Make a change in your rails views and see the change instantly.

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/x7msEo"

Template Source

Review the code before running this template on your machine.

gem_group('development') do
  gem 'guard'
  gem 'guard-livereload', require: false
  gem 'rack-livereload'
end

run 'bundle install'
run 'guard init'

File.open(Rails.root.join("config/application.rb"), "r+") do |file|
  lines = file.each_line.to_a
  config_index = lines.find_index("  class Application < Rails::Application\n")
  lines.insert(config_index + 1, "    config.middleware.insert_after ActionDispatch::Static, Rack::LiveReload if Rails.env.development?\n")
  file.rewind
  file.write(lines.join)
end

Mark
© 2020 GoRails, LLC