你用 Sinatra 做什么?
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Sinatra 不是 Rails。它是一个用于简单网站的微框架,您可能只需要定义一些操作。您可以将 Sinatra 应用程序设计得尽可能复杂,但是您会遇到这样的情况:您的代码比 Rails 更快变得一团糟。
虽然不是 100% 准确,但 Sinatra 主要适合 页面控制器 架构模式,而 Rails 是一种清晰的架构模式MVC 实现。
具体回答您的问题:
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:
我们目前正在使用 Sinatra 进行生产项目(尚未部署,仍处于开发阶段)。
基本上,它围绕遗留应用程序使用的数据库,并在内部向其他应用程序公开 REST Web 服务,以便它们可以与遗留应用程序交互,而无需直接访问数据库。
Rails 被考虑过,但没有使用,因为:
考虑到这些要求,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:
Given these requirements Rails is usable, but overkill, where as Sinatra hits the spot nicely.
对我的回答持保留态度(因为我之前没有实际部署过 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.
我们将 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.