aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2015-11-13 23:00:48 +0100
committerXavier Noria <fxn@hashref.com>2015-11-13 23:00:48 +0100
commitfdf5d4dfc30ce5a599392305567c0230c21b9b84 (patch)
treeb69dd43fbe8971fe7304e79861b4d565e8a1e7a4 /guides/source
parentc83d1e5508b27d810e37f11cec036a69697d26b8 (diff)
parent2ae24ddc31e706b0a7f5360cebe0e5c996eb6de4 (diff)
downloadrails-fdf5d4dfc30ce5a599392305567c0230c21b9b84.tar.gz
rails-fdf5d4dfc30ce5a599392305567c0230c21b9b84.tar.bz2
rails-fdf5d4dfc30ce5a599392305567c0230c21b9b84.zip
Merge pull request #22112 from claudix/master
Added warning on coding engine controllers [ci skip]
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/engines.md21
1 files changed, 21 insertions, 0 deletions
diff --git a/guides/source/engines.md b/guides/source/engines.md
index f961b799f1..359796b1ff 100644
--- a/guides/source/engines.md
+++ b/guides/source/engines.md
@@ -239,6 +239,27 @@ NOTE: The `ApplicationController` class inside an engine is named just like a
Rails application in order to make it easier for you to convert your
applications into engines.
+NOTE: Because of the way that Ruby does constant lookup you may run into a situation
+where your engine controller is inheriting from the main application controller and
+not your engine's application controller. Ruby is able to resolve the `ApplicationController` constant, and therefore the autoloading mechanism is not triggered. See the section [When Constants Aren't Missed](autoloading_and_reloading_constants.html#when-constants-aren-t-missed) of the [Autoloading and Reloading Constants](autoloading_and_reloading_constants.html) guide for further details. The best way to prevent this from
+happening is to use `require_dependency` to ensure that the engine's application
+controller is loaded. For example:
+
+``` ruby
+# app/controllers/blorgh/articles_controller.rb:
+require_dependency "blorgh/application_controller"
+
+module Blorgh
+ class ArticlesController < ApplicationController
+ ...
+ end
+end
+```
+
+WARNING: Don't use `require` because it will break the automatic reloading of classes
+in the development environment - using `require_dependency` ensures that classes are
+loaded and unloaded in the correct manner.
+
Lastly, the `app/views` directory contains a `layouts` folder, which contains a
file at `blorgh/application.html.erb`. This file allows you to specify a layout
for the engine. If this engine is to be used as a stand-alone engine, then you