【发布时间】:2012-06-25 03:59:45
【问题描述】:
我有一个使用 caches_action 的控制器
controllers/bar_controller.rb:
caches_action :bar, :layout => false
鉴于这个动作,我会在布局中设置html标题。
views/foo/bar.html.erb:
<%= content_for :mytitle do "testing" end %>
这是我的布局文件:
views/layouts/application.html.erb:
<title><%= yield :mytitle %></title>
但是,这仅在开发中有效。在生产中,它不起作用。任何想法都值得赞赏。谢谢。
类似问题:Is there a workaround for ignored content_for blocks with caches_action and :layout => false?
【问题讨论】:
-
缓存可能正在开发中。当它确实在生产环境中缓存时,您是在告诉它忽略布局,并使用它从
content_for呈现什么。 -
缓存中是否忽略 content_for?
-
如果你在布局中产生 content_for 并传递
:layout => false,看起来是这样。来自the docs:“如果你传递:layout => false,它只会缓存你的动作内容。当你的布局有动态信息时这很有用。”
标签: ruby-on-rails caching content-for