tags:

views:

579

answers:

4

Im confused about Sinatra (the ruby framework).

Is it a lightweight Rails replacement or you can have them running side by side?

Can you do a web application (as in Rails)? For example a twitter clone?

+3  A: 

Take my answer with a bit of a grain of salt (because I haven't actually deployed a sinatra application before), but sinatra's "sweet spot" is micro-apps: tiny little applications where a full MVC framework would be overkill. With Sinatra, you can build an entire web app with a single file of code.

An example of a "micro app" is rubular (note, however, that I have no idea what framework it's written in). Rubular does one thing, and one thing very well. Using rails would be overkill.

Myron
+10  A: 

Sinatra is not Rails. It is a micro-framework used for simple websites where you may need to just define a few actions. You can make a Sinatra application as complex as you want to, but you'll hit a point where you code has become a crazy mess sooner than with Rails.

While not 100% accurate, Sinatra fits mostly into the Page Controller architectural pattern, and Rails is a clear MVC implementation.

To answer your questions specifically:

  • It is not intended to replace Rails
  • It can run side by side
  • You could create a twitter clone in Sinatra
hobodave
Thank you hobodave, very clear
Victor P
+3  A: 

We're currently using Sinatra for a production project (not deployed live yet, still in dev).

Basically it's wrapping around a database used by a legacy app, and exposing REST web services to other apps internally so they can interact with the legacy app without having to access the DB directly.

Rails was considered, but not used because:

  • No view layer (essentially views are just JSON/XML REST responses)
  • Model is implemented using Sequel (ActiveRecord sucks dealing with legacy DBs with quirky, non-standard structures, but Sequel is quite nice for this)
  • Controller and routing layer is quite simple (although there is some complex business logic implemented in Ruby backing it)

Given these requirements Rails is usable, but overkill, where as Sinatra hits the spot nicely.

madlep
A: 

We used Sinatra for http://tweetarium.com much like madlep's usecase the majority of the site is just AJAX calls, so the views are very simple.

We don't use an ORM, just serializing the JSON from the twitter API and caching it in TokyoCabinet

I personally think Sinatra is an excellent fit for APIs. Each version could be a different Sinatra app mounted at a different endpoint and you can run it inside of your Rails app.

MatthewFord