0

In environment.rb I can add the line

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

where 'foos' is a folder. This loads all files inside the foos folder. However it doesn't load any of its subdirectories.

If I knew the names of all the subdirectories in the 'foos' folder, this problem would have an easy solution:

%W[folder1 folder2 folder2].each { |f| f.config.load_paths += %W( #{RAILS_ROOT}/app/models/foos/#{f} ) }

However, I won't always know the names of all folders inside of 'foos'. Is there someway to do this:

config.load_paths += %W( #{RAILS_ROOT}/app/models/foos/#{**WILDCARD**} )

Thanks

user94154
  • 16,176
  • 20
  • 77
  • 116

1 Answers1

2

It looks like this other question has the type of solution you are looking for to get all the sub directories:

get all of the immediate subdirectories in ruby

You can use something like the following to point at a particular directory and get a list of all the sub directories of it:

Dir['/home/username/Music/*/']

This will return an array of all the paths to the sub directories of the Music folder.

Community
  • 1
  • 1
Pete
  • 17,885
  • 4
  • 32
  • 30
  • Looks good. Could you help me adapt that method to work with in environment.rb. For example, Dir.glob("**/") finds all the subdirectories of the *current* directory. I want to point to a different directory whose subdirectories I want to load. – user94154 Jun 21 '10 at 16:55
  • 1
    updated the answer to hopefully help you target a particular directory. – Pete Jun 21 '10 at 23:42