在带有 RoR 的大型项目中使用 ExtJS 的危险?

发布于 2024-07-06 16:31:58 字数 388 浏览 17 评论 0原文

我们正在使用 Ruby on Rails 框架(CRM 系统)开发一个相当大的应用程序,并正在考虑将其重写为使用 ExtJS,以便 Rails 只进行数据处理,而 ExtJS 将以类似桌面的方式完成所有浏览器繁重的工作。

有人对最好的方法有一些经验和提示吗? ExtJS 是否足够成熟,可以用于相对较大(且复杂)的应用程序? 那么 Rails 部分呢?这里最好的方法是什么?

编辑:

只是为了说清楚。 我更喜欢这样一种方式,即所有 javascript 客户端应用程序代码一次性加载(在应用程序启动时,最好作为一个压缩的 js 文件),然后仅使用 ajax 向 Rails 发送数据或从 Rails 发送数据应用程序。 另外,如果 ERB 可用于动态生成 Ext 应用程序元素,那就太好了。

We are developing a considerably big application using Ruby on Rails framework (CRM system) and are considering to rewrite it to use ExtJS so that Rails would just do the data handling, while ExtJS would do all the browser heavylifting in a desktop-like manner.

Anyone has some experience and hints about what would be the best approach? Is ExtJS mature enough to be used in relatively big (and complex) applications? And what about the Rails part - what would be the best approach here?

EDIT:

Just to make it clear. I would prefer to do it in such a way that all the javascript client side application code is loaded at once (at the start up of the application, optimally as one compressed js file) and then just use ajax to send data to and from Rails app. Also, it would be nice to have ERB available for dynamic generation of the Ext apliccation elements.

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

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

发布评论

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

评论(10

全部不再 2024-07-13 16:31:58

我目前有一个用 ExtJS 编写的非常大的桌面风格应用程序。 它曾经在 Perl 的 Catalyst MVC 框架之上运行,但是一旦整个视图层转换为基于 ExtJS 的桌面,我就开始迁移到 Ruby on Rails 模型和控制器。 它同样快(如果不是更快的话),并且更易于维护,并且代码库要小得多。

  • 确保将活动记录配置设置为在 json 中不包含模型的根名称,以便 Ext 的 JsonStore 读取记录时不会出现问题。 ActiveRecord BASE 上有一个名为 include_root_in_json 的选项,您必须设置为 false。

  • 确保在 Ext 中正确定义应用程序类并最大化代码重用,并且您将需要某种方法来清理 DOM 中未使用的节点。 除非您使用最新版本的 Safari 或 Firefox 3.1,否则 Javascript 性能可能会非常痛苦。

  • 您可能需要某种缓存方法,以便在加载页面时将服务器上的数据以 JSON 格式提供给您的应用程序。 这将减少通过 Ajax 的往返次数。

  • 一定要使用 Ext 的 WindowManager 和 StoreManager 对象,或者从 Ext.util.MixedCollection 中创建自己的对象

  • 在单独的、可管理的文件中开发代码,然后进行构建过程,将它们组合成一个文件,然后在其上运行 YUI 的压缩器或 Dean Edwards Packer 来压缩/混淆文件。 在各自的单个文件中提供所有 JS 和 CSS,包括 Ext 提供的文件。

I currently have an extremely large, desktop style app written in ExtJS. It used to run on top of Perl's Catalyst MVC framework, but once the entire View layer was converted to an ExtJS based desktop I started migrating to Ruby on Rails models and controllers. It is equally as fast, if not faster, and easier to maintain and has a much smaller code base.

  • Make sure that you set your active record config to not include the root name of the model in the json, so that Ext's JsonStore has no problem reading the records. There is an option on ActiveRecord BASE called include_root_in_json you have to set to false.

  • Make sure that you properly define your Application classes in Ext and maximize code re-use and you are going to want some sort of method to clean up unused nodes in the DOM. Javascript performance can be a real pain unless you are using the latest versions of Safari or Firefox 3.1.

  • You probably will want some sort of caching method for data on the server to be served to your application in JSON format at the time the page is loaded. This will cut down on the number of round trips via Ajax.

  • Definitely make use of Ext's WindowManager and StoreManager objects, or roll your own from Ext.util.MixedCollection

  • Develop your code in separate, managable files, then have a build process which combines them into a single file, and then run YUI's compressor or Dean Edwards Packer on it to compress / obfuscate the file. Serve all JS and CSS in their own single files, including the Ext supplied ones.

半夏半凉 2024-07-13 16:31:58

[2012 更新] ExtJS 被 Sencha 收购,后者提供 GPLv3许可证,以及两个商业许可证。

[2008 年 10 月评论] ExtJS 在技术优点上非常出色,但几个月前的许可惨败让我开始考虑其他框架 - 我现在根本不信任 ExtJS 的创建者。 我不喜欢他们如何措辞他们的许可证,以及他们如何假装是开源倡导者,同时显然试图从那些相信他们的人身上不公平地获利。

我只是出于道德原因反对使用 ExtJS。

[2012 update] ExtJS was acquired by Sencha, who offer a GPLv3 license, and two commercial licenses.

[2008-Oct comment] ExtJS is great on technical merits, but the fiasco with the licensing several months ago have led me to look at other frameworks - I don't trust the creators of ExtJS at all now. I don't like how they worded their license, and how they pretended to be open source advocates whilst obviously attempting to profit unfairly off those who believed them.

I'm only against using ExtJS on moral grounds.

厌味 2024-07-13 16:31:58

这属于米兰对我之前的答案的评论的回答,但作为这里的新人,我没有足够的声誉点来回复:

“sp is undefined”存在问题,这是 Rails 缓存的结果将 JavaScript 文件合并为一个大文件(否则将有数百个文件)。 缓存引入了一些带有换行符的奇怪错误,导致整个事情失败。 这让我抓狂了一段时间,但解决方案是将 Ruby 从 1.8.6(补丁级别 72)更新到最新的 1.8.7。 这解决了问题,因此如果您想查看,请再次检查(您需要进行全面刷新以击败资源缓存)。

我很高兴您以前接触过 Ext MVC 的东西。 目前我完全相信它一定很难理解,主要是因为缺乏示例、教程和演示。 然而,代码本身有相当详细的文档记录(至少是较新的代码,有很多需要清理)。

我目前正在重构几个关键类,然后才能准备好适当的“发布”。 当一切准备就绪时(我想需要几周时间),我将生成文档并设置一个包含一些演示和示例代码的快速站点。 完成后,我将在我的博客上发布一篇文章 (http://edspencer.net)。

我的目标是尝试提供一个框架,使编写此类应用程序变得更加简单,并建立一些约定。 目前,还没有构建 ExtJS 应用程序的共识或默认方式,因此我们可以采取的任何措施来推动这一趋势都将朝着正确的方向迈出一步! 非常欢迎提出意见和贡献。

This belongs in answer to Milan's comment on my previous answer, but as a newcomer here I don't have enough reputation points to reply there:

There was a problem with the "sp is undefined", which was a result of Rails' caching of the JavaScript files into one large file (there would be several hundred files otherwise). The caching introduced some weird bugs with newlines which threw the whole thing off. This had me pulling my hair out for a while, but the solution was to update Ruby from 1.8.6 (patch level 72) to the latest 1.8.7. This fixed the problem so please check it again if you want to have a look (you'll need to do a full refresh to beat the asset caching).

I'm glad you've come across the Ext MVC stuff before. At present I can fully believe it must be quite difficult to understand, mainly due to a lack of examples, tutorials and demos. The code itself is reasonably well documented however (at least the newer code anyway, there is a lot which needs clearing out).

I am currently in the process of refactoring a few key classes before it is ready for a proper 'release'. When that's ready (I'm thinking a couple of weeks), I will generate the documentation and set up a quick site with some demos and example code. When I've done so I'll put up a post on my blog (http://edspencer.net).

My aim with this is to try to provide a framework which will make writing this type of application much simpler, and to establish some conventions. Currently there is no consensus or default way of structuring ExtJS applications, so anything we can do to move that along will be a step in the right direction! Comments and contributions are more than welcome.

娇俏 2024-07-13 16:31:58

我已经成功部署了您所描述的那种大型 RoR/ExtJS 应用程序(“单页”客户端 AJAX 驱动)。 Ext_scaffold 几乎是一个转移注意力的东西。

让 RoR 和 ExtJS 顺利地协同工作并不太费力。 根本的选择是扩展 ExtJS 来“讲 Rails”,修补 RoR 来“讲 ExtJS”,还是在中间相遇。 这将取决于您团队的技能。

我采用了中间相遇策略,其中包括:

  • 扩展Ext.data.StoreExt.data.Record以了解Rails路由约定
  • Hack < code>Ext.grid.EditorPanel 和 Ext.form.BasicForm 与 ActiveRecord 关联良好地配合
  • 编写一些模块来扩展 ActiveRecord::BaseApplicationController 只需从 Ext.grid.EditorPanelExt.form.BasicForm 提交

就差不多了。

话虽如此,ExtJS 也有缺点。

  • 您将不得不亲自动手了解内部结构。 不要被演示所迷惑。
  • 社区文档很差并且以 PHP 为中心。
  • 来自以 Github/Lighthouse 为中心的 RoR 世界,使用 VBulletin 就像在 1998 年醒来一样。我的意思是,没有公共错误跟踪器,只有更新的论坛帖子(WTF?)。
  • 该代码有点过度设计。
  • 该团队已经失去了开源的可信度,因此他们也失去了开源的氧气。
  • 该团队似乎专注于与 GWT 的集成(有人能说“enterpri$ey”吗?)。

I've successfully deployed a large RoR/ExtJS app of the kind you describe ("single-page" client-side AJAX driven). Ext_scaffold is pretty much a red-herring.

It's not too taxing to get RoR and ExtJS working smoothly together. The fundamental choice is whether to extend ExtJS to "speak Rails", patch RoR to "speak ExtJS", or meet in the middle. It's going to depend where your team's skills are.

I adopted the meet-in-the-middle strategy, which includes:

  • Extend Ext.data.Store and Ext.data.Record to be aware of Rails routing conventions
  • Hack Ext.grid.EditorPanel and Ext.form.BasicForm to play well with ActiveRecord associations
  • Write some modules to extend ActiveRecord::Base and ApplicationController to simply commits from Ext.grid.EditorPanel and Ext.form.BasicForm

That's pretty much it.

Having said that, there are drawbacks to ExtJS.

  • You're going to have to get your hands dirty in the internals. Don't be beguiled by the demos.
  • The community documentation is poor and PHP-centric.
  • Coming from the Github/Lighthouse-centred RoR world, using VBulletin is like waking up in 1998. I mean, there's no public bugtracker just a forum post that's updated (WTF?).
  • The code is a bit over-engineered.
  • The team have lost Open Source credibility so they've lost Open Source oxygen.
  • The team appear to be focused integration with GWT (can anyone say "enterpri$ey"?).
巴黎夜雨 2024-07-13 16:31:58

您可能想看看 Netzke 框架,它被认为可以做到这一点:促进创建复杂的单页 Web 应用程序,并强调模块化方法。

Netzke的优点是:

  • 代码的可重用性和可扩展性。 一旦你制作了你的组件(客户端和服务器端),你就可以在任何地方重用它,与其他组件结合,或者通过继承来扩展它。

  • 效率。 每个组件的类仅从服务器加载(并评估)一次,这节省了大量服务器与客户端通信的时间。

  • 它是开源的,并且正在积极开发中。 它有现场演示和示例代码。

  • 它具有预构建的组件,您甚至无需接触 Ext JS 即可立即使用(只需在 Rails 中配置它们)

    它具有预

  • (由其作者)已将其用于复杂物流应用程序的实际开发。

Netzke的缺点是:

  • 代码还很年轻,社区规模较小。

如果您有兴趣,请查看此处的描述和设计细节:https://github.com /nomadcoder/netzke-core

现场演示/教程可以在这里找到:http://netzke-demo .herokuapp.com 和此处:http://yanit.heroku.com

You might want to have a look at the Netzke framework that is thought to do just that: facilitate creating complex one-page web-application with the emphasis on modular approach.

The advantages of Netzke are:

  • Reusability and extensibility of the code. Once you get your component (both client and server side) made, you can reuse it in any place, combine with other components, or event extend it with inheritance.

  • Efficiency. Class for every component is loaded from the server (and evaluated) only once, which saves a lot of time on server-client communication.

  • It's open source, and it's in active development. It has live demos and example code.

  • It has prebuilt components that you can use straight away without even touching Ext JS (just configure them in Rails)

  • It's been used (by its author) for real-life development of a complex logistics application.

Disadvantages of Netzke are:

  • The code is still young, and the community small.

If you're interested, have a look at the description and design details here: https://github.com/nomadcoder/netzke-core

Live demo/tutorials can be found here: http://netzke-demo.herokuapp.com and here: http://yanit.heroku.com

南巷近海 2024-07-13 16:31:58

Ext 绝对已经足够成熟来处理这种情况。 我目前正在开发一个包含大量 Ext 的 Rails 项目,最困难的部分肯定是使用 Rails 的 to_json 来渲染 Ext 可以读取的 JSON(对于数组、散列、模型,但失败了)验证等)

查看 Rails 的 ext_scaffold 插件。 我从这个开始,修改了它的 ActiveRecord/ActionView 扩展,直到它完成了我需要它做的事情。

Ext is definitely mature enough to handle this situation. I'm currently working on a Rails project with a lot of Ext, and the hardest part has definitely been working with Rails's to_json to render JSON that Ext can read (for arrays, hashes, models, which failed validation, etc.)

Check out the ext_scaffold plugin for Rails. I started with this and hacked away at its ActiveRecord/ActionView extensions until it did what I needed it to do.

末が日狂欢 2024-07-13 16:31:58

我也有一些使用 ExtJS 和 Rails 的经验。 使用该框架是免费获得一些漂亮的小部件的好方法。 如果您使用 REST 约定来开发单页应用程序,那么它也应该与框架很好地配合。 与 RJS 也能很好地配合。

以下是我对使用该框架的抱怨

  1. 您无法真正使用 flash[:notice],因为重新加载单页应用程序很愚蠢。 这使得传递验证通知和消息成为一件苦差事,因为您必须使用 RJS/javascript 方法来显示它们。

  2. 你不能太多使用 erb,因此你必须将很多逻辑封装到 json 回调中。

    你不能太多使用 erb,因此

I has some experience using ExtJS with Rails too. Using the framework is a great way to get some nice looking widgets for free. REST convention should sit well with the framework too if you use it to develop single page applications. Works well with RJS too.

Here are my gripes with using the framework

  1. You can't really make use of flash[:notice] since reloading a single page application is silly. This makes passing validation notices and messages a chore since you have to use RJS/ javascript methods to show them.

  2. You can't use erb much thus you have to encapsulate a lot of the logic into the json callbacks.

獨角戲 2024-07-13 16:31:58

我已经为许多应用程序部署了 ExtJS 和 Rails,它们当然可以相互通信。 我们已经在 http:// /demo.domine.co.uk/admin。 现在忽略前端,因为它还不完整 - 管理部分基本上已经完成,您可以使用以下命令登录:

用户名:edward
密码:rarrar

由于演示尚未完全完成,现阶段我不保证它在除 Firefox 之外的任何其他平台上都能正常工作。 它没有理由不能在其他浏览器中工作,我只是还没有花时间测试它们。 不过,重点更多的是与 Rails 的集成。

开始菜单上的每个应用程序都通过 JSON 与 Rails 后端交互。 我已经编写了一个基本的 Rails 插件来为我们完成大部分工作。 我将很快发布其背后的代码,但现在希望这能让人们了解这两种技术如何协同工作......

I've deployed ExtJS and Rails for a number of applications and they certainly can be made to talk to each other. We've put together a quick demo of an app we're currently developing in Rails + Ext at http://demo.domine.co.uk/admin. Ignore the front end for now as it's not complete - the admin section is essentially finished and you can log in to it with:

username: edward
password: rarrar

As the demo's not completely finished yet I won't guarantee that it works correctly in anything other than Firefox at this stage. There's no reason for it not to work in other browsers, I just haven't spent any time testing them yet. The point is more about the integration with rails though.

Every application on the start menu is interacting with the Rails backend via JSON. I've written a basic Rails plugin to do most of the work for us there. I'll be releasing the code behind that shortly but for now hopefully that gives some idea of how well these two technologies can work together...

树深时见影 2024-07-13 16:31:58

虽然我没有 ExtJS 的经验(除了阅读“实用 Rails 项目" 书)我使用了 jQuery Flexigridjrails 以获得更多桌面感觉。

效果非常好。

While I have no experience of ExtJS (besides reading about in the "Practical Rails Projects" book) I used a jQuery Flexigrid with jrails to get more of a desktop feel.

That worked pretty well.

捎一片雪花 2024-07-13 16:31:58

好的。 我在很多项目中使用extjs gxt gwt,并且它非常容易开发。 但我想告诉你,我用 extjs+gwt (gxt) 构建了我的项目,我不确定 Ruby。
链接文本

Ok. I use extjs gxt gwt on many project, and it very easy for develop. But I want to tell you that I built my project with extjs+gwt (gxt), I don't sure about Ruby.
link text

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