on Rails和骨干相结合的Ruby [英] Combining Ruby on Rails and Backbone

查看:154
本文介绍了on Rails和骨干相结合的Ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道这个相当长的一段时间,还没有真正找到一个这样的答案。

I was wondering this for quite a while and haven't really found an answer for this yet.

为什么你会使用Backbone.js的exaclty Rails应用程序里面?难道是扩展功能,为您的JS更MVC模式,建立更好的API ...?

Why would you use Backbone.js exaclty inside a Rails application? Is it to extend functionality, have a more MVC pattern for your JS, build better API's...?

目前,我看不出一个原因,你想用它来做什么,因为我不认为我明白Backbone.js的概念

At the moment I can't see a reason why you would want to use it for something, because I don't think I understand the concept of Backbone.js

推荐答案

轨的一大好处是,你有一个平台和一种语言,你使用它来处理服务器 - code和能够生成客户端 - code(使用视图)。

The big advantage of rails is that you have one platform and one language that you use that will handle the server-code and can generate the client-code (using the views).

毫无疑问,这理论上的优势迅速开始打滑,一旦你想提高JavaScript和jQuery的用户体验。所以,其实你还是要学两种语言。

Undoubtedly this theoretical advantage quickly starts slipping once you want to improve your user-experience with javascript and jquery. So actually you still have to learn two languages.

但还是:所有的模型,业务规则,...是在Ruby中的服务器端处理。这也意味着服务器总是可到达的。

But still: all your models, business-rules, ... is handled on the server-side in Ruby. This also means that the server always has to be reachable.

什么是javacript /客户端MVC(如Backbone.js的,SproutCore的,...)可以为您提供一个更原生应用程序的感觉。一个单一的网页应用程序,例如像Gmail中。
根据您的要求有一些非常有效的用例这样的平台。例如。在具有低的连接地点或装置也可以是(使用HTML5)非常有用的一个网络的应用,这并不需要是在线的所有时间。当设备重新联机这可能数据和编辑内容保存到本地存储和同步回服务器/数据库。

What a javacript/client MVC (like Backbone.js, Sproutcore, ...) can offer you is a more native application feel. A single web-page application, like e.g. Gmail. Depending on your requirements there are some very valid use-cases for such a platform. E.g. in places or devices with low connectivity it could be very useful (with HTML5) to have a web-application that does not need to be "online" all the time. It could save data and edits to the local storage and sync back to the server/database when the device is back online.

但是,有一个很大的缺点开发使用Rails结合客户端MVC应用程序时:你会不得不做一些双线发展(这是相同的,当你使用Flex / Silverlight的)。您的模型将需要在服务器和客户端上所定义。我可以想像,一些可以改进,比如你实际使用presenter类,它在服务器端可以存储在不同的模型/表在客户端上的MVC。但还是会有的逻辑,模型复制...

But, there is a big disadvantage when developing client MVC applications in combination with Rails: you will have to do some double development (it is the same when you are using flex/silverlight). Your models will need to be defined both on the server and on the client. I can imagine that some improvements could be made, like on the client MVC you are actually using presenter-classes, which on the server-side could be stored in different models/tables. But still there will be duplication of logic, models, ...

所以这就是为什么我认为对于大多数应用,此刻,这不是明智的切换到某些客户端MVC框架。这将是一个大量的工作。

So that's why I think that for most applications, at the moment, it is not wise to switch to some client MVC framework. It will be a lot more work.

但是,当你需要一个真正的本地应用程序的外观和感觉,或单页的Web应用程序,那么JavaScript客户端MVC框架是要走的路。如果你需要一个客户端的MVC框架,我建议 SproutCore的

But when you do need the look and feel of a real native application, or a one-page-web application, then a javascript client MVC framework is the way to go. And if you do need a client MVC framework, I would propose Sproutcore.

要简单ajaxify当前的Rails应用程序(降低每一页的加载时间),看看 pjax护栏

To simply ajaxify your current rails application (reduces load-time of every single page), take a look at pjax-rails.

这篇关于on Rails和骨干相结合的Ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆