你用 Sinatra 做什么?

发布于 2024-08-18 05:31:27 字数 118 浏览 2 评论 0原文

我对 Sinatra(Ruby 框架)感到困惑。

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

你能做一个网络应用程序(如 Rails 中的那样)吗?例如 Twitter 克隆?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你列表最软的妹 2024-08-25 05:31:27

Sinatra 不是 Rails。它是一个用于简单网站的微框架,您可能只需要定义一些操作。您可以将 Sinatra 应用程序设计得尽可能复杂,但是您会遇到这样的情况:您的代码比 Rails 更快变得一团糟。

虽然不是 100% 准确,但 Sinatra 主要适合 页面控制器 架构模式,而 Rails 是一种清晰的架构模式MVC 实现。

具体回答您的问题:

  • 旨在取代Rails
  • 可以并排运行
  • 可以在Sinatra中创建一个twitter克隆

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
红衣飘飘貌似仙 2024-08-25 05:31:27

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

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

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

  • 没有视图层(本质上视图只是 JSON/XML REST 响应)
  • 模型是使用 Sequel 实现的(ActiveRecord 很难处理具有古怪、非标准结构的遗留数据库,但 Sequel 对此非常好) )
  • 控制器和路由层非常简单(尽管在 Ruby 中实现了一些复杂的业务逻辑来支持它)

考虑到这些要求,Rails 是可用的,但有点过头了,而 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.

刘备忘录 2024-08-25 05:31:27

对我的回答持保留态度(因为我之前没有实际部署过 sinatra 应用程序),但 sinatra 的“最佳点”是微应用程序:微小的应用程序,其中完整的 MVC 框架会显得大材小用。借助 Sinatra,您可以使用单个代码文件构建整个 Web 应用程序。

“微型应用程序”的一个例子是 rubular (但请注意,我不知道它是用什么框架编写的) 。 Rubular 只做一件事,而且做得很好。使用导轨就有点矫枉过正了。

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.

沙与沫 2024-08-25 05:31:27

我们将 Sinatra 用于 http://tweetarium.com,就像 madlep 的用例一样,网站的大部分内容只是 AJAX 调用,因此观点很简单。

我们不使用 ORM,只是从 twitter API 序列化 JSON 并将其缓存在 TokyoCabinet 中,

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文