Changeset 1093
- Timestamp:
- 10/02/08 00:06:55 (18 months ago)
- Location:
- rails_book/depot/app
- Files:
-
- 3 modified
- 1 moved
-
controllers/store_controller.rb (modified) (1 diff)
-
models/cart.rb (modified) (1 diff)
-
views/store/_cart_item.html.erb (modified) (1 diff)
-
views/store/add_to_cart.js.rjs (moved) (moved from rails_book/depot/app/views/store/add_to_cart.rjs) (1 diff, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
rails_book/depot/app/controllers/store_controller.rb
r1092 r1093 15 15 rescue ActiveRecord::RecordNotFound 16 16 logger.error("Attempt to access invalid product #{params[:id]}") 17 flash[:notice] = "Invalid product" 18 redirect_to :action => :index 17 redirect_to_index("Invalid product") 19 18 else 20 19 @cart = find_cart 21 @cart.add_product(product) 20 @current_item = @cart.add_product(product) 21 redirect_to_index unless request.xhr? 22 22 end 23 23 end -
rails_book/depot/app/models/cart.rb
r1090 r1093 7 7 8 8 def add_product(product) 9 cur rent_item= @items.find {|item| item.product == product}10 if cur rent_item11 cur rent_item.increment_quantity9 cur = @items.find {|item| item.product == product} 10 if cur 11 cur.increment_quantity 12 12 else 13 @items << CartItem.new(product) 13 cur = CartItem.new(product) 14 @items << cur 14 15 end 16 cur 15 17 end 16 18 -
rails_book/depot/app/views/store/_cart_item.html.erb
r1091 r1093 1 <tr> 1 <% content_tag(:tr, 2 :id => cart_item == @current_item ? 'current_item' : nil) do %> 2 3 <td><%= cart_item.quantity %>×</td> 3 4 <td><%= h(cart_item.title) %></td> 4 5 <td class="item-price"><%= number_to_currency(cart_item.price) %></td> 5 < /tr>6 <% end %> -
rails_book/depot/app/views/store/add_to_cart.js.rjs
r1092 r1093 1 1 page.replace_html("cart", :partial => "cart", :object => @cart) 2 page['current_item'].visual_effect :highlight, 3 :startcolor => '#88ff88', :endcolor => '#114411'
