How do you load all directories recursively in the models and lib directories? In application.rb, I have the lines:
config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')] config.autoload_paths += Dir[Rails.root.join('lib', '{**}')]
but they only seem to add one level of model and lib subdirectories.
Thanks
Linux recursive directory listing using ls -R command. The -R option passed to the ls command to list subdirectories recursively.
By default, ls lists just one directory. If you name one or more directories on the command line, ls will list each one. The -R (uppercase R) option lists all subdirectories, recursively.
Grep command is used to search text from files. It is a versatile pattern that invokes grep with –r. –R option search files recursively from subdirectories, starting from the current directory. The command is run from the top-level directory.
Alternatively referred to as recursive, recurse is a term used to describe the procedure capable of being repeated. For example, when listing files in a Windows command prompt, you can use the dir /s command to recursively list all files in the current directory and any subdirectories.
this should be helpful
Dir["#{config.root}/app/models/**/","#{config.root}/lib/**/"]
enjoy! (:
Update:
Excellent question, posting example above i have simply referred to my recent project.
After making some tests, better understanding comes to me and it is great.
The main difference is of course neither in join method of File not config.root / Rails.root
Trailing '/' after '**' makes sense.
First one talks to match only directories when globbing. Second one talks do it recursively.
In your case this one could be also appropriate
Dir[ Rails.root.join('app', 'models', '**/') ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With