ruby-on-railsrubyspring-gem

How to use the event-based file system listener with Spring in a Rails 4.1 application


I'm using Spring 1.1.3 with the default Polling Watcher in a Rails 4.1.4 application. Now I'd like to give the event-based file system listener a try, but can't figure out how to configure this properly.

When adding the listen Gem (1.3.1) to the Gemfile and setting Spring.watch_method = :listen in an initializer, the Watcher doesn't change. Checking Spring.watcher will return an instance of Spring::Watcher::Polling.

So, where's the right place to configure this?


Solution

  • To configure Spring before Rails loads, set Spring.watch_method = :listen in config/spring.rb. Setting it in an app initializer is too late—you've already "sprung" by then.