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. -- Posted via http://www.ruby-forum.com/.
Brian Ablaza wrote:> I need to show a directory listing of a folder outside of the Rails app > structures = `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://<server>/<controller>/foop --Al Evans -- Posted via http://www.ruby-forum.com/.
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://<server>/<controller>/foop > > --Al EvansThanks 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 <pre> Dir["*"].sort_by {|f| test(?M, f)}</pre>. In my Ruby version, I just chdir to set the working directory. Ideas? -- Posted via http://www.ruby-forum.com/.
Brian Ablaza 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 <pre> Dir["*"].sort_by {|f| test(?M, f)}</pre>. 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 -- Posted via http://www.ruby-forum.com/.
> 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 EvansYeah, it works. I didn''t realize that you could use a string as a file ref that way. Thanks, Al. -- Posted via http://www.ruby-forum.com/.