From 8681058cf1bd53562ca3cb5bc40da91feb895863 Mon Sep 17 00:00:00 2001 From: Ryan Cook Date: Wed, 9 May 2012 09:59:22 -0600 Subject: [PATCH] Add `app/decorators` in the host Rails application to Rails autoload paths. Describe the reasoning behind each hook/callback. -- Issue #32 --- lib/draper/railtie.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/draper/railtie.rb b/lib/draper/railtie.rb index f0c9a32..2981f6a 100644 --- a/lib/draper/railtie.rb +++ b/lib/draper/railtie.rb @@ -3,10 +3,28 @@ require 'rails/railtie' module Draper class Railtie < Rails::Railtie + ## + # Decorators are loaded in + # => at app boot in non-development environments + # => after each request in the development environment + # + # This is necessary because we might never explicitly reference + # Decorator constants. + # config.to_prepare do ::Draper::System.load_app_local_decorators end + ## + # The `app/decorators` path is eager loaded + # + # This is the standard "Rails Way" to add paths from which constants + # can be loaded. + # + config.before_initialize do |app| + app.config.paths.add 'app/decorators', :eager_load => true + end + initializer "draper.extend_action_controller_base" do |app| ActiveSupport.on_load(:action_controller) do Draper::System.setup(:action_controller)