aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2013-02-11 15:19:38 +0100
committerYves Senn <yves.senn@gmail.com>2013-02-11 15:22:11 +0100
commit9e23399c3004afc6110c93d3df89c5209d39b20f (patch)
tree3d0b055ba0862dc06abed9266c67c71c557a9b6a
parentfdf04fe7f6250d7cca8a62850396b8807cff0633 (diff)
downloadrails-9e23399c3004afc6110c93d3df89c5209d39b20f.tar.gz
rails-9e23399c3004afc6110c93d3df89c5209d39b20f.tar.bz2
rails-9e23399c3004afc6110c93d3df89c5209d39b20f.zip
fix the example code in the engines guide. closes #8583.
-rw-r--r--guides/source/engines.md8
1 files changed, 8 insertions, 0 deletions
diff --git a/guides/source/engines.md b/guides/source/engines.md
index 028c0f3e3a..00939c4ff2 100644
--- a/guides/source/engines.md
+++ b/guides/source/engines.md
@@ -650,6 +650,14 @@ self.author = Blorgh.user_class.find_or_create_by(name: author_name)
Resulting in something a little shorter, and more implicit in its behavior. The `user_class` method should always return a `Class` object.
+Since we changed the `user_class` method to no longer return a
+`String` but a `Class` we must also modify our `belongs_to` definition
+in the `Blorgh::Post` model:
+
+```ruby
+belongs_to :author, class_name: Blorgh.user_class.to_s
+```
+
To set this configuration setting within the application, an initializer should be used. By using an initializer, the configuration will be set up before the application starts and calls the engine's models which may depend on this configuration setting existing.
Create a new initializer at `config/initializers/blorgh.rb` inside the application where the `blorgh` engine is installed and put this content in it: