레일 개발 환경에서 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'
...