【发布时间】:2011-01-02 20:39:42
【问题描述】:
我想这个问题以前有人问过,但即使我在 Google 上搜索过,我也没有找到解决方案。
这就是我在 Rails 2.3.5 中尝试做的事情:
layouts/application.html.erb:
<html>
<head>
... some other stuff
<%= yield :head %>
</head>
<body>
<% content_for :head, "something that belongs in the head" %>
</body>
</html>
注意 在 content_for 之前的产量。
我知道 Rails - 默认情况下 - 不允许在使用后定义 :head 的内容 yield 是有道理的。
我什至尝试挂钩到模板渲染过程,但到目前为止没有成功。
所以我的目标是能够在部分/模板中定义 content_for,并在响应发送到浏览器之前以某种方式延迟和执行“yield”。
有人想出了解决办法吗?
问候和感谢, 弗兰克
更新 我会按照 weppos 的想法去尝试机架中间件。谢谢
【问题讨论】:
标签: ruby-on-rails rendering yield delay