Can't get Sinatra to run

494 views
Skip to first unread message

trans

unread,
Mar 16, 2009, 11:15:43 PM3/16/09
to sinatrarb
Hi--

I'm trying out Sinatra and I can't get it to do anything. I made a
script 'app.rb':

require 'sinatra'

get '/' do
"Hello World
end

Then when I do

$ ruby app.rb

It just runs the script that returns to the command prompt, but no web
server runs.

After this I created a config.ru file.

require 'app'
run Sinatra::Application

And run this with:

$ rackup config.ru

That gets a webrick server going, but navigating to the url I get
"Sinatra doesn't know this ditty."

What am I doing wrong?

Thanks.

Scott Taylor

unread,
Mar 16, 2009, 11:17:23 PM3/16/09
to sina...@googlegroups.com
trans wrote:
> Hi--
>
> I'm trying out Sinatra and I can't get it to do anything. I made a
> script 'app.rb':
>
> require 'sinatra'
>
> get '/' do
> "Hello World
> end
>

Is rubygems required in your environment?

> Then when I do
>
> $ ruby app.rb
>
> It just runs the script that returns to the command prompt, but no web
> server runs.
>
What error are you getting?

Ryan Tomayko

unread,
Mar 16, 2009, 11:20:34 PM3/16/09
to sina...@googlegroups.com

Any chance you have a "sinatra.rb" file laying around in your working
directory? From a previous experiment, maybe?

Thanks,
Ryan

trans

unread,
Mar 17, 2009, 7:44:01 AM3/17/09
to sinatrarb
Okay. It took some rooting around in Sinatra's source, but I found the
issue. So the problem arises b/c of this code in Sinatra:

# we assume that the first file that requires 'sinatra' is the
# app_file. all other path related options are calculated based
# on this path by default.
set :app_file, lambda {
ignore = [
/lib\/sinatra.*\.rb$/, # all sinatra code
/\(.*\)/, # generated code
/custom_require\.rb$/ # rubygems require hacks
]
path =
caller.map{ |line| line.split(/:\d/, 2).first }.find do |file|
next if ignore.any? { |pattern| file =~ pattern }
file
end
path || $0
}.call

This is clearly not a robust solution, and it's causing the problem in
my case b/c I use Rolls, which is another library manager that works
like RubyGems. It's possible for others to jerry with the require
system too. So Sinatra needs a more robust way of figuring this out.
But I'm not sure how it can.

T.

Ryan Tomayko

unread,
Mar 17, 2009, 7:46:36 AM3/17/09
to sina...@googlegroups.com

Sinatra's trying to be clever there. You can specify the app_file explicitly:

set :app_file, __FILE__

Thanks,
Ryan

trans

unread,
Mar 17, 2009, 7:53:41 AM3/17/09
to sinatrarb


On Mar 17, 7:46 am, Ryan Tomayko <r...@tomayko.com> wrote:

> Sinatra's trying to be clever there. You can specify the app_file explicitly:
>
>     set :app_file, __FILE__

Cool. That did the trick.

Thanks,
T.

Max A

unread,
Mar 17, 2009, 11:06:03 AM3/17/09
to sinatrarb
I hit this problem, too. I altered the first ignore regex in the set
app_file lambda so that it takes the directory of that library file
(File.dirname(__FILE__)), goes up a directory, and subsequently
ignores all .rb files in that directory and subdirectories. Might be
a more robust solution.
Reply all
Reply to author
Forward
0 new messages