Directory Listing outside of app structure

I need to show a directory listing of a folder outside of the Rails app
structure. Moving the folder is not an option. In fact, changing
anything (including modes) is not possible for the folder.

I have working directory listing code in Ruby, but if I call chdir in
Rails to set the working directory to a folder outside the app tree,
nothing is returned to the browser. It’s fine if I chdir to a folder
inside the public folder.

To get this to work in Ruby, I needed to change the UID for the Ruby
file. I don’t think this approach will work in Rails.

I understand the security issues here, but would like to somehow say
that it’s safe to chdir to a particular directory. I can’t find any
discussion of Rails safety/security similar to the $SAFE information in
the Pickaxe book.

Brian A. wrote:

I need to show a directory listing of a folder outside of the Rails app
structure

s = ls /path/to/file

seems to work for me, unless there’s something I’m not understanding
about your requirements. For example,

def foop
render :text => ls -l /opt/local/share
end

produces the expected output for http:////foop

–Al Evans

Al Evans wrote:

s = ls /path/to/file

seems to work for me, unless there’s something I’m not understanding
about your requirements. For example,

def foop
render :text => ls -l /opt/local/share
end

produces the expected output for http:////foop

–Al Evans

Thanks for the response, Al. I should have been clearer. I’m working on
a directory indexer, so I need a listing equivalent to what you’d get
with

 Dir["*"].sort_by {|f| test(?M, f)}
. In my Ruby version,
I just chdir to set the working directory.

Ideas?

Brian A. wrote:

Thanks for the response, Al. I should have been clearer. I’m working on
a directory indexer, so I need a listing equivalent to what you’d get
with

 Dir["*"].sort_by {|f| test(?M, f)}
. In my Ruby version,
I just chdir to set the working directory.

Maybe I’m still missing something, but except for the formatting,

def foop
foo = Dir[’/opt/local/share/*’].sort_by {|f| test(?M, f)}
render :text => foo
end

seems to work for me.

–Al Evans

Maybe I’m still missing something, but except for the formatting,

def foop
foo = Dir[’/opt/local/share/*’].sort_by {|f| test(?M, f)}
render :text => foo
end

seems to work for me.

–Al Evans

Yeah, it works. I didn’t realize that you could use a string as a file
ref that way. Thanks, Al.