Force reload! from lib directory in rails 3.2 console
Asked Answered
E

1

2

I have a simple class in a file in lib/simple.rb.

In the console (rails c) I have a couple of problems:

  1. Rails seems unable to load the file even though application.rb contains config.autoload_paths += %W(#{config.root}/lib/**). How to make Rails 3.2 behave like Rails 2.x used to (I never had problems in Rails 2.x with this autoload stuff - Rails 3 seems like a step back :( )

  2. If I make a change to simple.rb and call reload! in console, it does not reload the file. I have to do load "#{Rails.root}/lib/simple.rb to make it reload. Is there a way to make reload! work like it used to in Rails 2.x? i.e. just make it reload all files without having to use load at all?

Ethbun answered 22/9, 2012 at 7:16 Comment(0)
F
2

It should be the folder containing the class you want to load. Therefore, should be

config.autoload_paths += %W(#{config.root}/lib)

If your app is threadsafe!, change config.autoload_paths to config.eager_load_paths. Once you do this, reload! should behave as you've described.

Fidelity answered 30/9, 2012 at 12:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.