Live code reload for your Rails app

Hello, Let me share a wonderful gem that can bring support of live code reload for your Rails app:

Just add a gem and that’s all.

Check the demo: rails_live_reload

Look forward to seeing your comments and stars on GitHub :slight_smile:

3 Likes

you know, guard already does that pretty well

1 Like

I know. But do you know the last real changes in the code happened 6 years ago? Or that it doesn’t support turbo, or requires lot’s of dependencies just based on gemspec file + I can imagine how those dependencies require another and so on. Plus it doesn’t know anything about Turbo.

And most important, have you actualy tried it? Because locally I get this:

Installing guard 2.18.0
ode .
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
    current directory: /Users/admin/.rvm/gems/ruby-3.1.1/gems/eventmachine-1.2.7/ext
/Users/admin/.rvm/rubies/ruby-3.1.1/bin/ruby -I /Users/admin/.rvm/rubies/ruby-3.1.1/lib/ruby/3.1.0

And finally,

It’s just not convenient and requires more effort.

2 Likes

This gem is really nice, @igorkasyanchuk! I’ve been using guard-livereload for a long time. But with rails_live_reload it seems I don’t have to install a plugin in the browser neither start a monitor process manually. These two points themselves are a compelling reason for me to migrate. I’ve also found that other of your gems can be quite useful to me, like the rails_charts. Thank you for sharing!

thank you @repoles such comments help to stay motivated and work on the opensource. By the way, there are more cool gems, full list is here https://www.railsjazz.com/ :slight_smile:

2 Likes

So far works for me. Guard live reload doesn’t work for us glr it doesn’t work over https, and we run https in dev. So this is fantastic! Thanks!

thank you for your feedback! Please share with your friends and put a star :slight_smile: or even make a contribution, since we have a bunch of todo’s

First, thanks for this. It seems to work great so far.

Second, it’s been a very long time since I’ve done any Rails development work so I am likely not recalling things well. I thought that Rails had hot code reloading straight out of the box. It appears that I’m wrong.

P.S. I might also be mis-interpreting this from the “Getting Started with Rails” guide:

In the development environment, Rails does not generally require you to restart the server; changes you make in files will be automatically picked up by the server.

But the way I read that, no special gems or additional configuration is needed to get auto-reloads.

Thanks (in advance) to anyone willing to cure my ignorance here!

P.P.S. I just realized that this line from the guide probably just means that the server need not be restarted for code changed to be picked up but that the browser will still need to be refreshed—which the gem listed above solves for. Still odd that this isn’t something Rails does out of the box. Seems like an obvious productivity enhancement.

yeap, you are right, Rails supports only code reload (on the next request), but not live code reload for CSS/ERB/etc

Hey @igorkasyanchuk. Just a quick feedback: unfortunately rails_live_reload didn’t work for me. I don’t know exactly why, but frequently it tries to reload a page and nothing happen. Actually, it does trigger the browser reload action, but the reload never ends. I mean, the reloading icon keeps spinning forever. No request is issued to the Rails app, so nothing is logged. After that, I can’t even stop the webserver process normally. I am forced to kill it. I’m using a Rails 6.1 alongside with Hotwire Turbo.

Don’t know how to help. If you can make a simple app that can be used to replicate the issue it will help. Also please open issue on the github page for this repo. Thanks

1 Like

Thank you @igorkasyanchuk for sharing your gem, I just tried it today. I had to use the config below to make it reload reliably, perhaps that would be a better default? I also changed my IDE to auto-save my edits every few seconds in order to trigger the reload.

# config/initializers/rails_live_reload.rb
RailsLiveReload.configure do |config|
  config.watch %r{app/views/.*}, reload: :always
  config.watch %r{app/assets/stylesheets/.*}, reload: :always
  config.watch %r{app/javascript/.*}, reload: :always
  config.watch %r{app/helpers/.*}, reload: :always
  config.watch %r{config/locales/.+\.yml}, reload: :always
end if defined?(RailsLiveReload)

I just run vintage watch.rb from Brett Terpstra 2011 on the whole project folder and it seems to reload fine with any change happening in the project. … am I missing out?

1 Like