What do you use Sinatra for?

Viewed 11306

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?

4 Answers

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

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.

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.

Related