我有一个疯狂的问题,只有在生产中才会发生。我根本不能在开发中复制它。
出于各种原因,我有以下设置:
class OrdersController < PublicController
class PublicController < CommonController
class CommonController < ApplicationController在CommonController中,我有一个类似这样的方法:
def mobile_ready
# set request format
if mobile_view?
request.format = :mobil
self.class.layout 'apps/dmvcs'
else
request.format = :html
end
end下面是事情变得奇怪的地方:
在OrdersController中,我有这样的功能:
before_filter :mobile_ready在PublicController中,我有这样的功能:
layout :select_layout
protected
def select_layout
mobile_view? ? 'public_mobile' : 'public'
end我已经跟踪了调用的顺序,并且在select_layout之前调用了mobile_ready方法,我认为应该这样做。
但令人难以置信的是,orders页面在上面的考试中没有使用公共布局呈现!!??它使用“app/dmvcs”布局(WTF!?)进行渲染。我检查了一遍又一遍,还有mobile_view?在桌面上是假的,但它仍然使用错误的布局。
更奇怪的是,如果我有这个:
class PublicController < CommonController
layout 'public' # set this so there is a default layout
layout :select_layout 它70%的时间都在工作,这意味着它可能会呈现正确的布局,也可能不会!?
以前有没有人见过这样的东西?这显然看起来像是某种奇怪的缓存或nginx问题,但我不知道该怎么做。
谢谢!
发布于 2012-11-29 01:28:03
这让我抓狂,我不是100%我有正确的解决方案,但长话短说,我删除了
self.class.layout 'apps/dmvcs' 我在CommonController中读到了一些线程安全问题,然后我将PublicController中的select_layout方法更改为:
def select_layout
if mobile_view?
if request.format == :mobile
'apps/dmvcs'
else
'public_mobile'
end
else
'public'
end
end现在,这一切似乎都在起作用。我不得不继续监测,但这是恼人的,见鬼。希望这能帮助其他人避免在before_filter中设置布局,除非他们想要处理Rails缓存/线程问题!
https://stackoverflow.com/questions/13608683
复制相似问题