2012-11-28 25 views
0

我有一個瘋狂的問題,只有在生產中發生。我不能在開發中複製它。生產問題與隨機佈局和before_filters

因爲我有以下設置各種原因:

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 

我跟蹤的調用和mobile_ready方法的順序select_layout之前被調用,因爲我相信它應該是。

但是,什麼是INCREDIBLY奇怪的是,訂單頁面不與上述考試中的公共佈局渲染!! ??它使用'app/dmvcs'佈局進行渲染(WTF !?)。我檢查了三重檢查和mobile_view?在桌面上是FALSE,但它仍然使用錯誤的佈局。

得到什麼離奇是,如果我有這樣的:

class PublicController < CommonController 
    layout 'public' # set this so there is a default layout 
    layout :select_layout 

它的工作原理的70%的時間,這意味着它可能使正確的佈局或者它可能不是!?

以前有誰見過類似的東西嗎?這顯然是一種奇怪的緩存或nginx問題,但我不知道該怎麼做。

謝謝!

回答

0

這驅使我堅果和我不是100%我有正確的解決方案,但我刪除

 self.class.layout 'apps/dmvcs' 

從CommonController我讀到一些線程安全問題,然後我改變了select_layout長話短說方法PublicController這樣:

def select_layout 
if mobile_view? 
    if request.format == :mobile 
    'apps/dmvcs' 
    else 
    'public_mobile' 
    end 
else 
    'public' 
end 
end 

而這一切都似乎現在是工作。生病不得不繼續監測,但這是令人討厭的。希望這可以幫助別人避免在before_filter中設置佈局,除非他們想要處理Rails緩存/線程問題!