Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
LiveReload with Rails app on Windows.

LiveReload for Rails App on Windows

Install gems

Gemfile:

group :development do
  gem 'guard-livereload'
  gem "rack-livereload"
  gem 'wdm', '>= 0.1.0' if Gem.win_platform?
end

bundle install.

Init guard

initialize guard:

guard init livereload

It will create the file 'Guardfile':

guard 'livereload' do
  watch(%r{app/views/.+\.(erb|haml|slim)$})
  watch(%r{app/helpers/.+\.rb})
  watch(%r{public/.+\.(css|js|html)})
  watch(%r{config/locales/.+\.yml})
  # Rails Assets Pipeline
  watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html|png|jpg))).*}) { |m| "/assets/#{m[3]}" }
end

Environment config 'config/environments/development.rb':

Myrails::Application.configure do
  config.middleware.use Rack::LiveReload
  ...
  
end  

Change settings appropriately:

# Specifying Rack::LiveReload options.
config.middleware.use(Rack::LiveReload,
  :min_delay        => 500,    # default 1000
  :max_delay        => 10_000, # default 60_000
  :live_reload_port => 56789,  # default 35729
  :host             => 'myhost.cool.wow',
  :ignore           => [ %r{dont/modify\.html$} ]
)

read more: https://github.com/johnbintz/rack-livereload.

Install browser plugin

for Chrome: https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei?hl=en. for Firefox: http://download.livereload.com/2.0.8/LiveReload-2.0.8.xpi.

Read more: http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-

Run guard

Run this command in Windows command prompt:

guard

It will run guard that will waiting for a browser connection:

...
06:41:05 - INFO - LiveReload is waiting for a browser to connect.

Open your browser and enable LiveReload. Guard will say something like that:

06:41:05 - INFO - Guard is now watching at 'D:/myprojects/path/site
←[0F[1] guard(main)> 06:41:17 - INFO - Browser connected.

Try change a view and see how browser reloads the page with your changes.

←[0F[1] guard(main)> oading browser: app/views/home/index.html.haml

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment