2009-06-13 2 views
5

레일 개발 환경에서 cache_classes이 꺼져 있으므로 app/ 아래의 코드를 수정하고 서버를 다시 시작하지 않고 변경 사항을 확인할 수 있습니다.cache_classes가 해제 된 미들웨어의 도메인 객체는 어떻게 사용합니까?

그러나 모든 환경에서 미들웨어는 한 번만 생성됩니다. 나는이 같은 미들웨어 그래서 만약 :

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

이것은 레일의 버그가 나타납니다. Rails 버전을 2.3.4 또는 2.3.5로 업그레이드 할 수 있는지 확인하십시오.

나는 this이 문제를 해결했다는 것을 믿습니다. 원본 버그보고는 here입니다.

-1

몇 시간 전에 당신과 비슷한 문제가 발생했습니다. 필자는 environment.rb의 time_zone을 utc로 설정하여이를 해결할 수 있음을 기억한다. 그것은 얼마 전이었고 config 매개 변수 이름이나 'UTC'또는 : utc인지 정확하게 기억하지 못했습니다. 시도 해봐, 아마도 도움이 될거야.

관련 문제