Ruby on rails development from scratch (windows) (13)-Order (Order)

Source: Internet
Author: User

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,

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.