局部的控制器动作 [英] Controller action for partials

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

问题描述

我试图为我的rails应用程序中的一个partials创建一个动作,但想知道如何命名它。它在开始有下划线吗?喜欢:

  def _my_partial 

end
pre>

还是没有下划线? 控制器指南中未提及

解决方案

partial 是嵌入在主视图或另一个 partial partial 的目的通常是重复使用或使视图代码更清晰。



如果您需要使用动作呈现部分内容,则最好是:




I was trying to create an action for one of the partials in my rails application, but wondered how to name it. Does it have the underscore at the beginning? Like:

def _my_partial

end

or no underscore? Not mentioned in the controllers guide

解决方案

A partial is a piece of view which is embedded in the main view or within another partial. The purpose of a partial is typically for re-use or to making view code cleaner.

If you need to use an action to render a partial, then it's probably better to either:

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

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