Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do you use Sinatra for? [closed]

Tags:

ruby

sinatra

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?

like image 968
Victor Avatar asked Jan 16 '10 00:01

Victor


People also ask

Why you should always use Sinatra instead of rails?

Sinatra is much more lightweight, needs less resources, and does fewer things out of the box. Rails on the other hand is packed with features, comes with a ton of code, and makes it very easy to build complicated web applications in limited time, if you know how to use it.

What is Sinatra framework?

Sinatra is a free and open source software web application library and domain-specific language written in Ruby. It is an alternative to other Ruby web application frameworks such as Ruby on Rails, Merb, Nitro, and Camping. It is dependent on the Rack web server interface. It is named after musician Frank Sinatra.


2 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
like image 111
hobodave Avatar answered Oct 07 '22 19:10

hobodave


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.

like image 25
madlep Avatar answered Oct 07 '22 20:10

madlep