Rails 子控制器? [英] Rails Sub-controllers?

查看:52
本文介绍了Rails 子控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Rails 还很陌生,遇到了一个我不太明白的问题转向架构上正确"的做法.

I'm pretty new to Rails and have an issue which I can't quite get my head around as to the architecturally 'correct' way of doing it.

问题与我所谓的子控制器有关.场景是这个:

Problem relates to what I kinda call sub-controllers. The scenario is this:

我有一系列的页面,页面上是某种形式的面板,其中包含一些信息(想想 gitHub 右上角的用户面板).

I have a series of pages, on which is a panel of some form containing some information (think the user panel on gitHub top right).

所以,在我的应用程序中,我有为页面生成数据的控制器并渲染出很好的响应,但是当涉及到这个时面板,在我看来你想要某种控制器动作致力于生成此面板及其视图.

So, in my app, I have controllers that generate the data for the pages and render out the responses which is fine, but when it comes to this panel, it seems to me that you would want some sort of controller action dedicated to generating this panel and it's view.

问题是,你是怎么做这件事的?我如何渲染子"视图中的控制器?

Question is, how do you go about doing this? How do I render a 'sub controller' from within a view?

推荐答案

我会将逻辑放在帮助程序或模块中.(http://api.rubyonrails.org/classes/ActionController/Helpers/ClassMethods.html)

I would put the logic in a helper or a module. (http://api.rubyonrails.org/classes/ActionController/Helpers/ClassMethods.html)

然后在您希望显示这些内容的地方渲染部分.(http://api.rubyonrails.org/classes/ActionView/Partials.html)

Then render partials where you want these things displayed. (http://api.rubyonrails.org/classes/ActionView/Partials.html)

这篇关于Rails 子控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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