aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorDamien Mathieu <42@dmathieu.com>2013-10-24 13:33:13 +0200
committerDamien Mathieu <42@dmathieu.com>2013-10-24 13:33:13 +0200
commita0fe2f1fc8334ed083c82ca020cf91e9b1f0185b (patch)
tree2ba2e6b54ac21febf89ea7aae3df6f8f9136ee55 /guides
parentb8a538625af2c9a3442a27eff4cf8318ba812ce7 (diff)
downloadrails-a0fe2f1fc8334ed083c82ca020cf91e9b1f0185b.tar.gz
rails-a0fe2f1fc8334ed083c82ca020cf91e9b1f0185b.tar.bz2
rails-a0fe2f1fc8334ed083c82ca020cf91e9b1f0185b.zip
fix typo introduced when searching in markdown document with vim
Diffstat (limited to 'guides')
-rw-r--r--guides/source/engines.md28
1 files changed, 14 insertions, 14 deletions
diff --git a/guides/source/engines.md b/guides/source/engines.md
index b9be764528..af48768fe9 100644
--- a/guides/source/engines.md
+++ b/guides/source/engines.md
@@ -1,4 +1,4 @@
-Getting Started wiith Engines
+Getting Started with Engines
============================
In this guide you will learn about engines and how they can be used to provide additional functionality to their host applications through a clean and very easy-to-use interface.
@@ -598,7 +598,7 @@ By outputting `@post.author` using the `<%=` tag, the `to_s` method will be call
```
#<User:0x00000100ccb3b0>
-```i
+```
This is undesirable and it would be much better to have the user's name there. To do this, add a `to_s` method to the `User` class within the application:
@@ -611,7 +611,7 @@ end
Now instead of the ugly Ruby object output the author's name will be displayed.
#### Using a controller provided by the application
-i
+
Because Rails controllers generally share code for things like authentication and accessing session variables, by default they inherit from `ApplicationController`. Rails engines, however are scoped to run independently from the main application, so each engine gets a scoped `ApplicationController`. This namespace prevents code collisions, but often engine controllers should access methods in the main application's `ApplicationController`. An easy way to provide this access is to change the engine's scoped `ApplicationController` to inherit from the main application's `ApplicationController`. For our Blorgh engine this would be done by changing `app/controllers/blorgh/application_controller.rb` to look like:
```ruby
@@ -702,7 +702,7 @@ an application. Same goes for if you want to use a standard initializer.
For locales, simply place the locale files in the `config/locales` directory, just like you would in an application.
-Testing an enginie
+Testing an engine
-----------------
When an engine is generated there is a smaller dummy application created inside it at `test/dummy`. This application is used as a mounting point for the engine to make testing the engine extremely simple. You may extend this application by generating controllers, models or views from within the directory, and then use those to test your engine.
@@ -725,7 +725,7 @@ get :index, use_route: :blorgh
This tells the application that you still want to perform a `GET` request to the `index` action of this controller, just that you want to use the engine's route to get there, rather than the application.
-Improving enginie functionality
+Improving engine functionality
------------------------------
This section explains how to add and/or override engine MVC functionality in the main Rails application.
@@ -746,7 +746,7 @@ Here is some sample code to do this:
```ruby
# lib/blorgh/engine.rb
-module Blorghi
+module Blorgh
class Engine < ::Rails::Engine
isolate_namespace Blorgh
@@ -763,12 +763,12 @@ 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
-i
+
**Adding** `Post#time_since_created`,
```ruby
# MyApp/app/decorators/models/blorgh/post_decorator.rb
-i
+
Blorgh::Post.class_eval do
def time_since_created
Time.current - created_at
@@ -778,7 +778,7 @@ end
```ruby
# Blorgh/app/models/post.rb
-i
+
class Post < ActiveRecord::Base
has_many :comments
end
@@ -789,7 +789,7 @@ end
```ruby
# MyApp/app/decorators/models/blorgh/post_decorator.rb
-i
+
Blorgh::Post.class_eval do
def summary
"#{title} - #{truncate(text)}"
@@ -799,7 +799,7 @@ end
```ruby
# Blorgh/app/models/post.rb
-i
+
class Post < ActiveRecord::Base
has_many :comments
def summary
@@ -809,14 +809,14 @@ end
```
#### Implementing Decorator Pattern Using ActiveSupport::Concern
-i
+
Using `Class#class_eval` is great for simple adjustments, but for more complex class modifications, you might want to consider using [`ActiveSupport::Concern`](http://edgeapi.rubyonrails.org/classes/ActiveSupport/Concern.html). ActiveSupport::Concern manages load order of interlinked dependent modules and classes at run time allowing you to significantly modularize your code.
**Adding** `Post#time_since_created` and **Overriding** `Post#summary`
```ruby
# MyApp/app/models/blorgh/post.rb
-i
+
class Blorgh::Post < ActiveRecord::Base
include Blorgh::Concerns::Models::Post
@@ -832,7 +832,7 @@ end
```ruby
# Blorgh/app/models/post.rb
-i
+
class Post < ActiveRecord::Base
include Blorgh::Concerns::Models::Post
end