content_for在开发中起作用,但在生产中不起作用? [英] content_for works in development but not production?

查看:91
本文介绍了content_for在开发中起作用,但在生产中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用caches_action的控制器

I have a controller using caches_action

controllers / bar_controller.rb:

caches_action :bar, :layout => false

,鉴于此操作,我将在布局中设置html标题。

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 %>

这是我的布局文件:

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?

推荐答案

在启用缓存的环境中,Rails只会忽略content_for块。使用 ActionController :: Filters 计算值并将这些值存储在实例变量中。在布局中引用实例变量。

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.

这篇关于content_for在开发中起作用,但在生产中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆