aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/layouts_and_rendering.md
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-25 20:34:05 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-25 20:34:05 -0300
commit89e051ace345b6e5d652b039e55ce00eafe1ed6b (patch)
tree25e97617e7f1d6cf0b8755eb8c6040bc5de6858d /guides/source/layouts_and_rendering.md
parenteb2a8e317d7989bc209a669afd101d940b7e573f (diff)
parent117f09c5d1eb600908001bb7b5ee353756e56456 (diff)
downloadrails-89e051ace345b6e5d652b039e55ce00eafe1ed6b.tar.gz
rails-89e051ace345b6e5d652b039e55ce00eafe1ed6b.tar.bz2
rails-89e051ace345b6e5d652b039e55ce00eafe1ed6b.zip
Merge pull request #16738 from net-engine/guides-template-inheritance
Guides: Template Inheritance (new in guides, feature in since 3.1)
Diffstat (limited to 'guides/source/layouts_and_rendering.md')
-rw-r--r--guides/source/layouts_and_rendering.md36
1 files changed, 36 insertions, 0 deletions
diff --git a/guides/source/layouts_and_rendering.md b/guides/source/layouts_and_rendering.md
index 329d501ce0..b0e71035c0 100644
--- a/guides/source/layouts_and_rendering.md
+++ b/guides/source/layouts_and_rendering.md
@@ -563,6 +563,42 @@ In this application:
* `OldArticlesController#show` will use no layout at all
* `OldArticlesController#index` will use the `old` layout
+##### Template Inheritance
+
+Similarly to the Layout Inheritance logic, if a template or partial is not found in the conventional path, the controller will look for a template or partial to render in its inheritance chain. For example:
+
+```ruby
+# in app/controllers/application_controller
+class ApplicationController < ActionController::Base
+end
+
+# in app/controllers/admin_controller
+class AdminController < ApplicationController
+end
+
+# in app/controllers/admin/products_controller
+class Admin::ProductsController < AdminController
+ def index
+ end
+end
+```
+
+The lookup order for a `admin/products#index` action will be:
+
+* `app/views/admin/products/`
+* `app/views/admin/`
+* `app/views/application/`
+
+This makes `app/views/application/` a great place for your shared partials, which can then be rendered in your ERb as such:
+
+```erb
+<%# app/views/admin/products/index.html.erb %>
+<%= render @products || "empty_list" %>
+
+<%# app/views/application/_empty_list.html.erb %>
+There are no items in this list <em>yet</em>.
+```
+
#### Avoiding Double Render Errors
Sooner or later, most Rails developers will see the error message "Can only render or redirect once per action". While this is annoying, it's relatively easy to fix. Usually it happens because of a fundamental misunderstanding of the way that `render` works.