content_for works in development but not production?

浪尽此生 提交于 2019-12-10 11:49:55

问题


I have a controller using caches_action

controllers/bar_controller.rb:

caches_action :bar, :layout => false

and in the view of this action, I'ill setting html title in layout.

views/foo/bar.html.erb:

<%= content_for :mytitle do "testing" end %>

this is my layout file:

views/layouts/application.html.erb:

<title><%= yield :mytitle %></title>

However, this only work in development. In production, it does not work. Any idea is appreciated. thanks.

similar question: Is there a workaround for ignored content_for blocks with caches_action and :layout => false?


回答1:


Rails will simply ignore the content_for block in caching enabled environment. Use ActionController::Filters to compute the values and store those values in instance variables. Refer instance variables in layouts.



来源:https://stackoverflow.com/questions/11183361/content-for-works-in-development-but-not-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!