0

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?

Community
  • 1
  • 1
hey mike
  • 2,431
  • 6
  • 24
  • 29
  • Caching is probably off in development. When it *does* cache in production, you're telling it to ignore the layout, and with it, what would be rendered from `content_for`. – numbers1311407 Jun 25 '12 at 04:11
  • is content_for ignored in caches? – hey mike Jun 25 '12 at 04:12
  • 1
    If you yield the content_for in the layout and pass `:layout => false`, it seems so. From [the docs](http://api.rubyonrails.org/classes/ActionController/Caching/Actions.html): "If you pass :layout => false, it will only cache your action content. That’s useful when your layout has dynamic information." – numbers1311407 Jun 25 '12 at 04:16

1 Answers1

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.

pacholik
  • 8,607
  • 9
  • 43
  • 55