In the last content, we wrote the CHECKOUT processing. This time, we will display the shopping cart and order on a page, so that users can easily see their shopping situation when placing orders.
1. to modify the checkout. rhtml file, add the following code:
<% = Error_messages_for ("order") %>
<% = Render_component (: action => "display_cart") %>-
<% = Stylesheet_link_tag "scaffold", "depot",: media => "all" %>
Click the "checkout" link on the display_cart page to see that the checkout page has changed,
2. But as we can see, in the upper right corner of the page, the Checkout link is also displayed. Of course we need to remove it. Return to the code added above:
<% = Render_component (: action => "display_cart") %>
Render_component actually displays the entire display_cart page. Now let's add a parameter so that it can distinguish whether it is on the display_cart page or the checkout page.
On the checkout page, change the code added above:
<% = Render_component (: action => "display_cart",: params =>{: context =>: checkout}) %>
We can see that we have added a context parameter.
Modify the store_controller.rb file and the display_cart method as follows:
Def display_cart
@ Cart = find_cart
@ Items = @ cart. items
If @ items. empty?
Redirect_to_index ("Your cart is currently empty ")
End
If params [: context] =: checkout
Render (: layout => false)
End
End
Then, modify the display_cart.rhtml page, make a judgment on the situation where the context parameter is checkout, and then display it accordingly:
Put the original code:
<Ul>
<Li> <% = link_to 'continue shopping ',: action => "index" %> </li>
<Li> <% = link_to 'empty cart',: action => "empty_cart" %> </li>
<Li> <% = link_to 'checkout ',: action => "Checkout" %> </li>
</Ul>
To:
<Ul>
<Li> <% = link_to 'continue shopping ',: action => "index" %> </li>
<% Unless params [: context] ==: checkout-%>
<Li> <% = link_to 'empty cart',: action => "empty_cart" %> </li>
<Li> <% = link_to 'checkout ',: action => "Checkout" %> </li>
<% End-%>
</Ul>
OK. Now let's take a look at the effect,