我如何处理在轨3基于ajax的子组件? [英] How do I deal with ajax based sub components in rails 3?
问题描述
我重构一个Rails 3应用程序,并想知道如何最好地处理基于AJAX的子组件?
I'm refactoring a rails 3 application, and want to know how best to deal with ajax based sub components?
我有一个仪表盘控制器。这是通过仪表盘#秀行动呈现。
I have a 'dashboard' controller. Which is rendered via the 'dashboard#show' action.
和我现在希望能有一个基于AJAX的标签组件,它是仪表板的一部分。
And I now want to have an ajax based 'tabs' component, which is part of the dashboard.
我有两个可能的解决方案:
I have two possible solutions:
解决方案1:实现标签组件作为一个动作,例如仪表盘#标签(这是我目前的解决方案)。这给了我丑陋的助手:
solution 1: implement the tabs component as an action e.g. 'dashboard#tabs' (this is my current solution). This gives me ugly helpers:
- tabs_dashboard_path
解决方案2:implented它作为嵌套的资源,例如仪表盘/制表符#秀。这将给很好地命名为佣工例如:
solution 2: implented it as nested resource e.g. 'dashboard/tabs#show'. This will give nicely named helpers e.g.:
- dashboard_tabs_path
霸菱在脑海中,我有很多其他的Ajax组件,这将是最好的行动过程?
Baring in mind I have a lot of other ajax components what would be the best course of action?
如果我是用的解决方案2我的资源将成为深度嵌套的,他们只会有一个'秀'行动;这似乎有点太冗长我喜欢。
If I was to used solution 2 my resources would become deeply nested, and they would only have one 'show' action; this would seem a bit too verbose for my liking.
有关实例的路由将被指定为:
For instance the routes would be specified as:
resource :dashboard, :only => [:show], :controller => "users/dashboard" do
resource :tabs :only => [:show], :controller => "users/dashboard/tabs" do
resource :steps :only => [:show], :controller => "users/dashboard/tabs/steps"
#etc....
end
end
有一个好的轨道的方式来处理呢?
Is there a good rails way for dealing with this?
推荐答案
我倾向于保持我的控制器,除了极少数的行动,一个只处理基本的REST动词。因此,在多节目的情况下,我会保持单仪表盘#秀
并有谐音/布局来处理的标签。我的理由是,标签本身没有资源,也没有将我其实对他们进行任何的RESTful操作。
I tend to keep my controllers with very few actions, and one that only deals with the basic REST verbs. Therefore, in a multi-show situation, I'd keep the single dashboard#show
and have partials/layouts to handle the tabs. My rationale is that the tabs themselves are not resources, nor would I actually perform any RESTful actions on them.
这篇关于我如何处理在轨3基于ajax的子组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!