mirror of https://github.com/rails/rails
When a collection is empty, render returns nil.
This commit is contained in:
parent
36b640e4b5
commit
3a7c16dbb9
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue