CACHE_CLASSES를 사용하여 미들웨어의 도메인 객체를 어떻게 사용합니까?

StackOverflow https://stackoverflow.com/questions/991113

  •  13-09-2019
  •  | 
  •  

문제

Rails 개발 환경에서 cache_classes 아래에서 코드를 수정할 수 있도록 꺼져 있습니다 app/ 서버를 다시 시작하지 않고 변경 사항을 확인하십시오.

그러나 모든 환경에서 미들웨어는 한 번만 만들어집니다. 따라서 이와 같은 미들웨어가있는 경우 :

class MyMiddleware

  def initialize(app)
    @app = app
  end

  def call(env)
    env['model'] = MyModel.first
  end

end

그리고 나는 이것을한다 config/environments/development.rb:

config.cache_classes = false # the default for development
config.middleware.use MyMiddleware

그런 다음 항상 다음과 같은 오류를 얻을 수 있습니다.

A copy of MyMiddleware has been removed from the module tree but is still active!
  /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:414:in `load_missing_constant'
  /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:96:in `const_missing'
  /Users/me/projects/my_project/lib/my_middleware.rb:8:in `call'
  /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/middleware_stack.rb:72:in `new'
  ...

문제는 MyMiddleware 인스턴스는 시스템로드 시간에 한 번 생성되지만 MyModel 클래스는 각 호출마다 다시로드됩니다.

나는 시도했다 'MyModel'.constantize.first 방법 용도 시간까지 클래스에 대한 결합을 지연 시키지만 문제를 새로운 문제로 바꿉니다.

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.include?
  /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/active_record/attribute_methods.rb:142in `create_time_zone_conversion_attribute?'
  /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/active_record/attribute_methods.rb:75:in `define_attributes_methods'
  ...
도움이 되었습니까?

해결책

이것은 레일 버그 인 것 같습니다. 레일 버전을 2.3.4 또는 2.3.5로 업그레이드 할 수 있는지 확인하십시오.

나는 믿는다 이것 문제를 해결 한 커밋입니다. 원래 버그 보고서입니다 여기.

다른 팁

우리는 얼마 전에 당신과 비슷한 문제를 겪었습니다. 내가 기억하는 한, 이것은 Environment.rb to : utc에서 time_zone을 설정하여 해결할 수 있습니다. 시간이 오래 전과 나는 config 매개 변수 이름 또는 'UTC'인지 : UTC인지 정확히 기억하지 못합니다. 시도해보십시오. 아마도 도움이 될 것입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top