-
的使用有什么区别和 =
在下面的:
- content_for :header do
%h1 Title
和
= content_for :header do
%h1 Title
什么是正确的方法?
最佳答案
这取决于你想做什么。
要立即渲染标题,请执行以下操作:
= content_for :header do
%h1 Title
要存储内容并稍后使用,请执行以下操作:
- content_for :header do
%h1 Title
并在您的 View 中的某处使用它:
= content_for :header
在 Rails < 3.2 中,您需要使用
= yield :header
. Rails 3.2 仍然支持它,但它在帮助模块中不起作用,而 content_for
确实(感谢@drewish)。
关于ruby-on-rails - 在 HAML 上下文中使用 Rails `content_for` 助手的正确语法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12843266/