I run an project on Sinatra, now it has a lot of files a sub-directories, so I want to view a list of those files with their respective directory. For example, I put in the address bar "localhost:4567/landing/" where landing is the container of some pages, but it throw me this "Sinatra doesn’t know this ditty." Is there a way to do that. I hope you understand what I'm asking.
Asked
Active
Viewed 1,223 times
1 Answers
4
Sinatra doesn't deal with the local file system, it deals with HTTP routes. For example, the '/'
in get '/' do
refers to the root url of your website, not the root directory of your website. In order to list the local files, you would need to use the Ruby Dir
class, something like this:
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
get '/' do
Dir.entries('.').map { |e| "<p>#{e}</p>" }
end
Edit: Of course, it's dangerous to work with the filesystem directly, even using routes, so I would recommend that you get a better understanding of what is going on behind the scenes by reading up a little.

Josh Voigts
- 4,114
- 1
- 18
- 43