Tuesday, January 06, 2009

Sinatra made me go ROOOOAARRRR.

So I wanted to give Sinatra a try today because I had to throw up, quite literally, a one-one dynamic webapp. No tests, no helpers, nothing -- just the one page with some Ruby-powered bits on the backend. The only reason I wanted Sinatra was because I wasn't in the mood to do a massive svn check-in of a vendored rails with the project.

So, sudo gem install sinatra and we're off to the races, right? Wrong. After about 10 minutes of debugging I realize that the Sinatra gem, a) doesn't work with the latest Rack (0.9), and b) seems to be updated infrequently judging by some blog posts I've read. They recommend grabbing Sinatra from github, but there's no stable Git branch available. I don't know if they're using the master branch as the stable branch or what. Doesn't matter, because I don't know what revision of Sinatra works with what copy of Rack. >:(

So I do the next best thing, which is to downgrade Rack to 0.4, which is what the Sinatra gem requires.

Which works. For a bit, until I need to serve up a static html file. I guess that functionality isn't in the Sinatra gem. Some blogs mention how to use the 'public/' directory, which I tried, and failed miserably at; I'm assuming that functionality is somewhere in the github version of Sinatra and not in the gem.

Right around that point I gave up and just cracked out a full-blown Rails project. I copied the logic over, had it up and running in about 7 minutes, which was a stark contrast to the ~2/hrs I spent trying to get Sinatra working.

Lesson?

Next time, just use the latest edge version of Sinatra and hope there are no bugs in it.

This time, I'll just waste two minutes watching the '...'s go by.

2 comments:

karmi said...

Hi Arron,

the static files are *served* from the ./public dir, as the Readme states (see http://sinatra.rubyforge.org), but they're *available* at http://localhost:4567/whatever.static -- just like in Rails.

The Rack issue was indeed weird.

If you encounter any more hiccups, please do shoot a ticket: http://sinatra.lighthouseapp.com/

Karel

Radical Ed said...

Ah, that was my mistake I suppose.

I was assuming since Sinatra didn't appear to do any kind of url rewriting that files in /public would be accessed via /public rather than /.