何时使用Helpers而不是Partials [英] When to use Helpers instead of Partials

查看:70
本文介绍了何时使用Helpers而不是Partials的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Rails应用程序中,您将在哪种情况下使用部分服务,何时使用帮助程序?我发现两者非常相似,因为它们代表标记片段.

In a rails application, in which situation would you use a partial and when would you use a helper? I find both very similar, since they represent markup fragments.

这是否有约定?使用它们的轨道方式"是什么?

Is there a convention around this? which is the 'rails way' of using them?

谢谢!

推荐答案

我想我的经验法则是使用帮助程序来构建单个的显示单位"(例如包含链接的跨度)并使用用于构建更复杂的显示单元的部分,该显示单元由多个显示"单元组成,例如网格或菜单.

I guess my rule of thumb is to use a helper to build a single "unit" of display -- like a span containing a link -- and to use a partial to build a more complex unit of display composed of more than one "unit" of display -- like a grid or a menu.

这篇关于何时使用Helpers而不是Partials的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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