0

I have a rails app in development mode.

When I make changes to a ruby class called 'Dummy' under lib/dummy it doesn't get automatically reloaded, until I restart the rails server.

The class lives in a file under

lib/dummy/dummy.rb

class Dummy
  def test
    puts "XXX #{var_that_does_not_exist.stuff} XXX"
  end
end

If I run this, the controller that calls

dummy = Dummy.new
dummy.test

causes an error as the variable 'var_that_does_not_exist' doesn't exist. If I updated the code to remove that variable, and make another request it continues to fail, until I actually restart the rails server.

development.rb contains

  config.cache_classes = false
  config.reload_classes_only_on_change = false
  config.serve_static_assets = false

application.rb contains

# Autoload lib/ folder including all subdirectories
config.autoload_paths += Dir["#{config.root}/lib/**/"]
config.autoload_paths += Dir["#{config.root}/lib/duummy/"]
Dave
  • 656
  • 2
  • 6
  • 22
  • Yup thats because any changes made in **lib** folder only take effect after the server is restarted. The lib folder is primarily for initialization and stuff you do before the server is started and tasks/things that run independent of the server state. – Minato Oct 14 '15 at 11:30
  • Thanks, this does seem to be the case, I mis-understood the autoload config – Dave Oct 21 '15 at 11:08
  • so is it working fine now? – Minato Oct 21 '15 at 11:09
  • please have a look at this [question](http://stackoverflow.com/questions/4074830/adding-lib-to-config-autoload-paths-in-rails-3-does-not-autoload-my-module) it's related to you use-case? – Minato Oct 21 '15 at 11:12

0 Answers0