你用什么Sinatra?

时间:2022-03-10 21:04:52

Im confused about Sinatra (the ruby framework).

我对Sinatra(红宝石框架)感到困惑。

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

它是一个轻量级的Rails替代品还是你可以让它们并排运行?

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

你可以做一个Web应用程序(如在Rails中)吗?比如一个twitter克隆?

4 个解决方案

#1


62  

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.

Sinatra不是Rails。它是一个用于简单网站的微框架,您可能只需要定义一些操作。您可以将Sinatra应用程序设置为您想要的复杂程序,但是您可能会比使用Rails更快地将代码变成一个疯狂的混乱。

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

虽然不是100%准确,但Sinatra主要适用于页面控制器架构模式,而Rails是一个明确的MVC实现。

To answer your questions specifically:

要具体回答你的问题:

  • It is not intended to replace Rails
  • 它不是要取代Rails
  • It can run side by side
  • 它可以并排运行
  • You could create a twitter clone in Sinatra
  • 你可以在Sinatra中创建一个推特克隆

#2


17  

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

我们目前正在使用Sinatra进行生产项目(尚未部署,仍在开发中)。

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.

基本上它围绕着遗留应用程序使用的数据库,并在内部向其他应用程序公开REST Web服务,以便他们可以与遗留应用程序进行交互,而无需直接访问数据库。

Rails was considered, but not used because:

考虑了Rails,但没有使用,因为:

  • No view layer (essentially views are just JSON/XML REST responses)
  • 没有视图层(本质上是视图只是JSON / XML REST响应)
  • Model is implemented using Sequel (ActiveRecord sucks dealing with legacy DBs with quirky, non-standard structures, but Sequel is quite nice for this)
  • 模型是使用Sequel实现的(ActiveRecord很糟糕,处理古怪的数据库与古怪的非标准结构,但续集相当不错)
  • Controller and routing layer is quite simple (although there is some complex business logic implemented in Ruby backing it)
  • 控制器和路由层非常简单(尽管在Ruby支持的情况下实现了一些复杂的业务逻辑)

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

鉴于这些要求Rails是可用的,但是过度杀伤,而Sinatra很好地击中了这个位置。

#3


5  

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.

我的答案有一点点(因为我之前没有真正部署过sinatra应用程序),但是sinatra的“甜蜜点”是微应用程序:一个小的应用程序,其中一个完整的MVC框架将是矫枉过正。使用Sinatra,您可以使用单个代码文件构建整个Web应用程序。

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.

“微应用程序”的一个例子是rubular(但请注意,我不知道它写的是什么框架)。 Rubular做了一件事,有一点非常好。使用rails会有点矫枉过正。

#4


1  

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.

我们在http://tweetarium.com上使用Sinatra很像madlep的用例,大部分网站只是AJAX调用,因此视图非常简单。

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

我们不使用ORM,只是从twitter API序列化JSON并在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.

我个人认为Sinatra非常适合API。每个版本可以是安装在不同端点的不同Sinatra应用程序,您可以在Rails应用程序内运行它。

#1


62  

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.

Sinatra不是Rails。它是一个用于简单网站的微框架,您可能只需要定义一些操作。您可以将Sinatra应用程序设置为您想要的复杂程序,但是您可能会比使用Rails更快地将代码变成一个疯狂的混乱。

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

虽然不是100%准确,但Sinatra主要适用于页面控制器架构模式,而Rails是一个明确的MVC实现。

To answer your questions specifically:

要具体回答你的问题:

  • It is not intended to replace Rails
  • 它不是要取代Rails
  • It can run side by side
  • 它可以并排运行
  • You could create a twitter clone in Sinatra
  • 你可以在Sinatra中创建一个推特克隆

#2


17  

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

我们目前正在使用Sinatra进行生产项目(尚未部署,仍在开发中)。

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.

基本上它围绕着遗留应用程序使用的数据库,并在内部向其他应用程序公开REST Web服务,以便他们可以与遗留应用程序进行交互,而无需直接访问数据库。

Rails was considered, but not used because:

考虑了Rails,但没有使用,因为:

  • No view layer (essentially views are just JSON/XML REST responses)
  • 没有视图层(本质上是视图只是JSON / XML REST响应)
  • Model is implemented using Sequel (ActiveRecord sucks dealing with legacy DBs with quirky, non-standard structures, but Sequel is quite nice for this)
  • 模型是使用Sequel实现的(ActiveRecord很糟糕,处理古怪的数据库与古怪的非标准结构,但续集相当不错)
  • Controller and routing layer is quite simple (although there is some complex business logic implemented in Ruby backing it)
  • 控制器和路由层非常简单(尽管在Ruby支持的情况下实现了一些复杂的业务逻辑)

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

鉴于这些要求Rails是可用的,但是过度杀伤,而Sinatra很好地击中了这个位置。

#3


5  

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.

我的答案有一点点(因为我之前没有真正部署过sinatra应用程序),但是sinatra的“甜蜜点”是微应用程序:一个小的应用程序,其中一个完整的MVC框架将是矫枉过正。使用Sinatra,您可以使用单个代码文件构建整个Web应用程序。

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.

“微应用程序”的一个例子是rubular(但请注意,我不知道它写的是什么框架)。 Rubular做了一件事,有一点非常好。使用rails会有点矫枉过正。

#4


1  

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.

我们在http://tweetarium.com上使用Sinatra很像madlep的用例,大部分网站只是AJAX调用,因此视图非常简单。

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

我们不使用ORM,只是从twitter API序列化JSON并在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.

我个人认为Sinatra非常适合API。每个版本可以是安装在不同端点的不同Sinatra应用程序,您可以在Rails应用程序内运行它。