Automatically loading Rails in the user directory

Rails has a function when models, controllers, views, libraries, etc. automatically load when they are needed. This is especially useful in development mode, where they also automatically restart.

How can I say that Rails performs an automatic download, somewhere it does not expect files to load? Let's say I create a folder app/addonsor something else, and I want it to load classes in the same way that models loaded. Therefore, if I have app/addons/foo.rb, I want to be able to call the class Foo.

+3
source share
2 answers

In the config / environment.rb file, add the following line to the Rails :: Initializer.run block:

config.load_paths + =% W (# {RAILS_ROOT / app / addons})

+4
source

In your .rb environment, there should be a line like this:

config.load_paths += %W( #{RAILS_ROOT}/lib/ #{RAILS_ROOT}/app/addons/ )

Just add another path you need.

+1
source

Source: https://habr.com/ru/post/1757234/


All Articles