Changeset 1093

Show
Ignore:
Timestamp:
10/02/08 00:06:55 (18 months ago)
Author:
vasi
Message:

hilight

Location:
rails_book/depot/app
Files:
3 modified
1 moved

Legend:

Unmodified
Added
Removed
  • rails_book/depot/app/controllers/store_controller.rb

    r1092 r1093  
    1515    rescue ActiveRecord::RecordNotFound 
    1616      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") 
    1918        else 
    2019          @cart = find_cart 
    21           @cart.add_product(product) 
     20          @current_item = @cart.add_product(product) 
     21          redirect_to_index unless request.xhr? 
    2222        end 
    2323  end 
  • rails_book/depot/app/models/cart.rb

    r1090 r1093  
    77   
    88  def add_product(product) 
    9     current_item = @items.find {|item| item.product == product} 
    10     if current_item 
    11       current_item.increment_quantity 
     9    cur = @items.find {|item| item.product == product} 
     10    if cur 
     11      cur.increment_quantity 
    1212    else 
    13       @items << CartItem.new(product) 
     13      cur = CartItem.new(product) 
     14      @items << cur 
    1415    end 
     16    cur 
    1517  end 
    1618   
  • 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 %> 
    23      <td><%= cart_item.quantity %>&times;</td> 
    34      <td><%= h(cart_item.title) %></td> 
    45      <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  
    11page.replace_html("cart", :partial => "cart", :object => @cart) 
     2page['current_item'].visual_effect :highlight, 
     3  :startcolor => '#88ff88', :endcolor => '#114411'