As far as I know, that statement causes a variable to be created called
'cart' that is available to the partial, and whose value is @cart. In
addition, the file that contains the partial must be named
_cart.html.erb.
In the partial file _cart.html.erb, you can then do something like this:
and rails didn't complain. So, which variable name should you use? To
me it seems much clearer to use @cart. It highlights the links between
the various files and makes it easier to know where the cart/@cart value
came from.
and rails didn't complain. So, which variable name should you use? To
me it seems much clearer to use @cart. It highlights the links between
the various files and makes it easier to know where the cart/@cart value
came from.
The way I understand this syntax is that the value of @cart will be made
available in the partial as a local variable cart.
Imaging you had this instead:
<%= render(:partial => "cart", :object => @some_cart) %>
In this case the local variable for the partial would still be cart.
Taken from :partial => "cart" and from :object => @some_cart. However,
@some_cart would still be accessible from inside the partial because the
partials can see all the instance variable assigned in the controller.
In this case the local variable for the partial would still be cart.
Taken from :partial => "cart" and from :object => @some_cart. However,
@some_cart would still be accessible from inside the partial because the
partials can see all the instance variable assigned in the controller.