views:

1344

answers:

7

Im getting interested in Sinatra to develop micro web applications.

I'm not sure where to draw the line when choosing between Sinatra and Rails.

Please can you provide some real life examples of applications in Sinatra in the web?

+1  A: 

Found this in the Sinatra documentation: http://www.calendaraboutnothing.com/

Victor P
A: 

I don't think you are going to find a lot of user-facing web applications using Sinatra. It's simply too lightweight to deal with any remotely complex domain. Maybe some microsite somewhere is using it...

Anyway, the line to draw is, does your problem involve a single or limited use web gui for a simple task, or is it a full-fledged application with lots of responsibilities? Sinatra is more suitable for the former, Rails for the latter, although hypothetically either could be used for both.

floyd
+2  A: 

Use Rails if you want everything that Rails is. Rails has a ton of nice helpers for routing and rendering HTML and a ton of other stuff. Rails is great.

Use Sinatra if you just want to get your Ruby code turned into web requests ASAP without the complexity and overhead of Rails. Sinatra is also great.

You can make a Sinatra app as complicated as you would like, but you might be better off using Rails if you want convenience methods. I tend to prefer Rails for complicated apps and use Sinatra more for APIs or less complex apps.

It should be noted that Rails 3 will allow you to write microframework like Sinatra and leave out as many parts of the Rails stack as you don't need...

semanticart
+6  A: 

many many http://www.sinatrarb.com/wild.html

Victor P
+3  A: 

hurl is an application developed during the '09 rails rumble. It's both an open source app and developed using sinatra.

Having a look at the code can definitely give you an idea of the type of things you can do with sinatra.

theIV
A: 
John Topley
Why didn't you link us to your shortened URL? :) Nice post, btw.
theIV
Heh, I should have done, shouldn't I? Thanks! :-)
John Topley
+3  A: 

In contrast with many people who came to Ruby through Rails, I started my Ruby language experience building a simple application with Sinatra. But the application got heavier over time and I considered porting it to Rails. I haven't however moved yet - instead I rebuilt some parts of the wheel and continued using Sinatra. Now I've a fairly complex web app running well & fine on Sinatra & ActiveRecords.

The reason I did not move to Rails were:

  1. jQuery A very important concern. I was heavily using jQuery in my Sinatra app (and I love jQuery). The 'prototype' way of JavaScript did not appeal to me and I wanted to use jQuery in my Rails app (with its helpers). I tried a rails plugin that said to do this, but it did not work well.

  2. Rewrite stuff like < a href > to use Rails Helpers Though not an end in itself, porting to Rails for me meant porting all my ugly HTML view code to nice looking Rails helpers. But this was a boring and time consuming task, and I skulked away.

  3. A primary key of mine broke the Rails requirement of having only integer primary key ids. I don't want to change my existing system.

  4. Inertia :)

Some of Rails features I felt Sinatra lacked in, but made up somehow in Sinatra are:

  • Well Defined MVC & Clean Directory Structure With the Rails MVC architecture came a lot of helper scripts (generate model, generate view, controller etc.) Rails maintains a clean directory structure for us. We can focus more on the application objects and the Rails conventions will take care of the folders and files. I managed this in Sinatra by splitting my controllers into different files and 'load'ing them from a main script. And was using ERB for the view templates and ActiveRecord for models. So much for MVC.

  • Migrations Yeah, couldn't live without them. But since I was using ActiveRecord, I could easily write migrate scripts with date as a version control mechanism.

  • Helpers Rails helpers are cool. But I wrote some for Sinatra when I needed it. But for most, I use Ruby+HTML in my ERB views. Not very bad though.

  • will_paginate Doesn't have it in Sinatra yet.

  • Easy page caching (fragments and stuff) :- Mine is not public facing site and web traffic is within bounds.

  • Partials :- Hey, Sinatra can do it :)

There are probably more that I'm missing from Rails. Luckily these are all I have noticed yet.

But I'm looking forward to Rails 3.0. It is said to be more modular and supports jQuery better. Till then, I'm happy with Sinatra - it does everything Rails does - but you might have to rebuild the wheel at times.

Jasim