I’ve been trying to find the “right” way to do this and I’m now
appealing to
the Rails masses.
I want to list all the directory names in a specific location and have
just
the directory names appear in a dropdown control for the user.
The Dir.entries(“somepath”) includes the “.” and “…” folders plus all
files
and folders.
The Dir.glob() is hard for me to work with. I’m not familiar with that
type
of search. Part of my problem is that it seems the best fit but I’m not
sure
how to make it work with any given directory path. It seems to work off
the
current one and I feared changing the current one and having odd bugs
when
concurrency issues arrise when the page is viewed more frequently and
different base directories are being searched.
that type of search. Part of my problem is that it seems the best
fit but I’m not sure how to make it work with any given directory
path. It seems to work off the current one and I feared changing
the current one and having odd bugs when concurrency issues arrise
when the page is viewed more frequently and different base
directories are being searched.
So, what is the right rails way to do this?
Thanks,
Mark E.
Mark-
You can use the [] bracket form of Dir to get what you want i think.
You can just pass it the full path to the dir you want. Or use
RAILS_ROOT to refer to the root of your rails app dir. Try something
like this:
aray of all the files in your apps public/files dir. does not
descend into subdirectories.
files = Dir["#{RAILS_ROOT}/public/files/*"]
aray of all the files in your apps public/files dir. this one does
descend into subdirectories.
files = Dir["#{RAILS_ROOT}/public/files/**/*"]
Cheers-
-Ezra
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.