【问题标题】:Production issue with random layouts and before_filters随机布局和 before_filters 的生产问题
【发布时间】:2012-11-16 12:24:51
【问题描述】:

我有一个只在生产中发生的疯狂问题。我根本无法在开发中复制它。

由于各种原因,我有以下设置:

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 之前被调用,我认为应该如此。

但令人难以置信的是,在上述考试中,订单页面没有以公共布局呈现!!??它使用“app/dmvcs”布局(WTF!?)呈现。我已经检查并三重检查和 mobile_view?在桌面上为 FALSE,但仍使用错误的布局。

如果我有这个,更奇怪的是:

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

它在 70% 的时间里都能正常工作,这意味着它可能会呈现正确的布局,也可能不会!?

有没有人见过这样的事情?显然,这似乎是某种奇怪的缓存或 nginx 问题,但我不知道该怎么做。

谢谢!

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 caching nginx before-filter


    【解决方案1】:

    这让我发疯了,我不是 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 缓存/线程问题!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 2019-04-11
      • 2019-10-13
      • 2023-04-02
      • 1970-01-01
      • 2011-05-19
      相关资源
      最近更新 更多