问题
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