Ruby Rails

Livereload Ruby on Rails applications

16 Mar 2014
1 minute read

Bored of manually reloading your Rails app after each and every ‘view’ change, including your SASS and Coffeescript files?

Let your computer to the tiresome work, thats what its been built for. The Livereload Gem together with the Rack::LiveReload Gem were made to accomblish that goal.

How to

Add the two Gems to your Gemfile inside the development group:

group :development do
  gem 'guard-livereload', require: false
  gem 'rack-livereload'
end

Create (or update) the Guardfile with

$ guard init livereload

If you use SASS, Coffescript, etc. edit the Guardfile to include them:

guard 'livereload' do
  ...
  watch(%r{(app|vendor)(/assets/\w+/(.+\.(sass|scss|css|js|coffee|html|png|jpg))).*}) { |m| "/assets/#{m[3]}" }
end

Then add the middleware to your Rails middleware stack by editing your config/environments/development.rb.

# Automatically inject JavaScript needed for LiveReload
config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload)

Bonus

Use Foreman to start up your Rails server as well as Guard and maybe other things you need to run your Rails app in development.