aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2013-05-24 11:24:00 -0500
committerSteve Klabnik <steve@steveklabnik.com>2013-05-24 11:24:00 -0500
commitab28bafc9f1118652f5090fa1260923118930518 (patch)
treea5cd6d9e46c81ff3d0abe7093dd8cf4e18b67fcd
parent432ffdb0739426122e216e0f7199ebc16f15de7e (diff)
downloadrails-ab28bafc9f1118652f5090fa1260923118930518.tar.gz
rails-ab28bafc9f1118652f5090fa1260923118930518.tar.bz2
rails-ab28bafc9f1118652f5090fa1260923118930518.zip
Add note about decorator loading in Engines guide.
Because decorators aren't referenced by the application, they won't get autoloaded. And because we recommend the pattern, it would be irresponsible to not show how to load them properly. Fixes #10647.
-rw-r--r--guides/source/engines.md26
1 files changed, 26 insertions, 0 deletions
diff --git a/guides/source/engines.md b/guides/source/engines.md
index 663e59b5c3..bc66ed256e 100644
--- a/guides/source/engines.md
+++ b/guides/source/engines.md
@@ -719,6 +719,32 @@ Engine model and controller classes can be extended by open classing them in the
For simple class modifications use `Class#class_eval`, and for complex class modifications, consider using `ActiveSupport::Concern`.
+#### A note on Decorators and loading code
+
+Because these decorators are not referenced by your Rails application itself,
+Rails' autoloading system will not kick in and load your decorators. This
+means that you need to require them yourself.
+
+Here is some sample code to do this:
+
+```ruby
+# lib/blorgh/engine.rb
+module Blorgh
+ class Engine < ::Rails::Engine
+ isolate_namespace Blorgh
+
+ config.to_prepare do
+ Dir.glob(Rails.root + "app/decorators/**/*_decorator*.rb").each do |c|
+ require_dependency(c)
+ end
+ end
+ end
+end
+```
+
+This doesn't apply to just Decorators, but anything that you add in an engine
+that isn't referenced by your main application.
+
#### Implementing Decorator Pattern Using Class#class_eval
**Adding** `Post#time_since_created`,