What is the difference between render :object and :collection?
Is it
- @cart have to put in :obj开发者_如何学JAVAect ?
- @cart.item have to put in : collection ?
Using :collection
will run the partial once for every item in the array. While you're in the partial, the name of the object will be the name of the partial. So if you have:
<%= render :partial => 'cart', :collection => @carts %>
Then in your partial (_cart.html.erb, for example) you can use the cart
object:
Cart Name: <%= cart.name %>
Here's a link to the documentation:
http://guides.rubyonrails.org/layouts_and_rendering.html
精彩评论