aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2013-02-11 10:14:49 -0800
committerSteve Klabnik <steve@steveklabnik.com>2013-02-11 10:14:49 -0800
commit67444ba1cb237939a8244e980387fe035436e1e5 (patch)
treecb76549bcee7612bbaa889c80ecbe01df4cb64cd
parent65dde28730fabadf95d99512cf8a11894a575234 (diff)
parent9e23399c3004afc6110c93d3df89c5209d39b20f (diff)
downloadrails-67444ba1cb237939a8244e980387fe035436e1e5.tar.gz
rails-67444ba1cb237939a8244e980387fe035436e1e5.tar.bz2
rails-67444ba1cb237939a8244e980387fe035436e1e5.zip
Merge pull request #9250 from senny/8583_fix_engines_documentation_example_code
fix example code in engines guide
-rw-r--r--guides/source/engines.md16
1 files changed, 12 insertions, 4 deletions
diff --git a/guides/source/engines.md b/guides/source/engines.md
index 8062b9c4ea..00939c4ff2 100644
--- a/guides/source/engines.md
+++ b/guides/source/engines.md
@@ -57,7 +57,7 @@ The `--full` option tells the generator that you want to create an engine, inclu
end
```
* A file at `lib/blorgh/engine.rb` which is identical in function to a standard Rails application's `config/application.rb` file:
-
+
```ruby
module Blorgh
class Engine < ::Rails::Engine
@@ -72,12 +72,12 @@ The `--mountable` option tells the generator that you want to create a "mountabl
* A namespaced `ApplicationHelper` stub
* A layout view template for the engine
* Namespace isolation to `config/routes.rb`:
-
+
```ruby
Blorgh::Engine.routes.draw do
end
```
-
+
* Namespace isolation to `lib/blorgh/engine.rb`:
```ruby
@@ -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:
@@ -789,7 +797,7 @@ module Blorgh::Concerns::Models::Post
extend ActiveSupport::Concern
# 'included do' causes the included code to be evaluated in the
- # context where it is included (post.rb), rather than be
+ # context where it is included (post.rb), rather than be
# executed in the module's context (blorgh/concerns/models/post).
included do
attr_accessor :author_name