我有一个使用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?
答案 0 :(得分:0)
Rails将在启用缓存的环境中忽略content_for块。使用ActionController::Filters
计算值并将这些值存储在实例变量中。在布局中引用实例变量。