aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides
diff options
context:
space:
mode:
authorMatt Burke <spraints@gmail.com>2011-09-02 10:20:23 -0400
committerMatt Burke <spraints@gmail.com>2011-09-02 10:20:23 -0400
commit3a7c16dbb9c1a4ea96c516c0a9f9ce5d34cee49a (patch)
treef432c3290f0060f99d2cacf202539621ca4b16aa /railties/guides
parent36b640e4b56673ade9cf10051dc7624db2497d3a (diff)
downloadrails-3a7c16dbb9c1a4ea96c516c0a9f9ce5d34cee49a.tar.gz
rails-3a7c16dbb9c1a4ea96c516c0a9f9ce5d34cee49a.tar.bz2
rails-3a7c16dbb9c1a4ea96c516c0a9f9ce5d34cee49a.zip
When a collection is empty, render returns nil.
Diffstat (limited to 'railties/guides')
-rw-r--r--railties/guides/source/layouts_and_rendering.textile7
1 files changed, 7 insertions, 0 deletions
diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile
index 310a70ca9b..3252f17c56 100644
--- a/railties/guides/source/layouts_and_rendering.textile
+++ b/railties/guides/source/layouts_and_rendering.textile
@@ -1093,6 +1093,13 @@ In Rails 3.0, there is also a shorthand for this. Assuming +@products+ is a coll
Rails determines the name of the partial to use by looking at the model name in the collection. In fact, you can even create a heterogeneous collection and render it this way, and Rails will choose the proper partial for each member of the collection:
+In the event that the collection is empty, +render+ will return nil, so it should be fairly simple to provide alternative content.
+
+<erb>
+<h1>Products</h1>
+<%= render(@products) || 'There are no products available.' %>
+</erb>
+
* +index.html.erb+
<erb>