SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 130 | Next

Ola Bini

"Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java"

order_lines.inject(0) do |sum,l|
sum + l.amount * l.product.price
end
render :action => 'handle'
end
end
end
CHAPTER 4 ?–  STORE ADMINISTRATION 65
There??™s lots of new information here. First of all, you??™ve added the admin layout so you get
a unified layout. Second, the parameters to the verify method have been changed, so the only
parameter includes remove and handled. The list method has been changed, so it only shows
orders where the status is 'placed'. This is so you can retain the orders in the database, but
you don??™t have to see them when they??™ve been handled.
There are also three new methods. Rails will call the handle method when a specific order
should be shown and handled. It finds the order in question, and then sums the total price
together.
The remove method removes the order in question from the database.
The handled method sets the status to "handled" on the order in question, and redirects
to the listing. Open up the app/views/orders/list.rhtml file and change it so it looks like this:

Orders to handle









<% for order in @orders %>







<% end %>
CustomerTimeAmountItems
<%= h order.customer %><%= order.time.strftime("%F %H:%M") %><%= money(order.order_lines.inject(0){
|sum,ol| sum + ol.amount*ol.product.price}) %>
<%= order.order_lines.inject(0){
|sum,ol| sum + ol.amount} %>
<%=
link_to "Handle order", :action => 'handle', :id => order %>

This shows a pleasing list of orders, showing the time each order was placed, how much
money it amounts to, and how many items there are.


Pages:
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142