本文介绍了使用Rails助手来渲染局部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,助手主要用于从某些特定于视图的逻辑中清理视图.

From my understanding, helpers are mainly used to clean up views from some view-specific logic.

但是在我当前的新项目(旧版应用程序)中,我偶然发现了许多看起来像这样的助手

But on my currently new project (legacy application), I've stumbled upon a lot of helpers that look like this

def itemprepare
  render :partial => 'items/itemlist_summary'
end

这是正确的吗?在视图中呈现局部视图似乎是您想要做的事情,因为它不包含任何需要抽象的逻辑.

Is this correct? Rendering a partial to me seems like something you would want to do in the view, as it doesn't include any logic that needs to be abstracted.

我应该内联所有这些助手吗?

Should I just inline all of these helpers?

推荐答案

渲染部分不属于助手.助手应该帮助您完成包含逻辑的事情.逻辑不属于控制器,除非逻辑是呈现部分并决定是否显示某些东西.

Rendering a partial doesn't belong in a helper. Helpers should help you to do things that contain logic. Logic doesn't belong in the controller unless it's logic to render partials and decide if something should be displayed or not.

这篇关于使用Rails助手来渲染局部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 14:36