Live Reload

Live reloads rails assets using guard
Icons/chart bar
Used 101 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

Comments
Fajarullah
Hi, thank you for created this template.
i think it's better to insert middleware config into development environment
by using `environment` method, which is like this
environment "config.middleware.insert_after ActionDispatch::Static, Rack::LiveReload", env: :development