Skip to content

Instantly share code, notes, and snippets.

@bhgames
Created June 21, 2010 15:12
Show Gist options
  • Save bhgames/446984 to your computer and use it in GitHub Desktop.
Save bhgames/446984 to your computer and use it in GitHub Desktop.
<% unless cart.line_items.empty? %>
<div class = "cart_title">Your Cart</div>
<table>
<%= render(cart.line_items)%>
<tr class="total_line">
<td colspan="2">Total</td>
<td class="total_cell"><%= number_to_currency(cart.total_price) %></td>
</tr>
</table>
<%= button_to 'Empty cart', cart, :method => :delete,
:confirm => 'Are you sure?' %>
<%end%>
<!DOCTYPE html>
<html>
<head>
<title> Pragprog Books Online Store</title>
<%= stylesheet_link_tag "scaffold" %>
<%= stylesheet_link_tag "depot", :media => "all"%>
<%javascript_include_tag :defaults %>
<% csrf_meta_tag %>
</head>
<body id = "store">
<div id="banner">
<%= image_tag("logo.png") %>
<%= @page_title || "Pragmatic Bookshelf" %>
</div>
<div id="columns">
<div id ="side">
<div id="cart">
<%= render @cart%>
</div>
<%=@time%><br />
<a href = "http://www....">Home</a><br />
<a href = "http://www....">Questions</a><br />
<a href = "http://www....">News</a><br />
<a href = "http://www....">Contact</a><br />
</div>
<div id ="main">
<%= yield %>
</div>
</div>
</body>
</html>
page.replace_html('cart',render(@cart))
page[:cart].visual_effect :blind_down if @cart.total_items==1
page[:current_item].visual_effect :highlight,
:startcolor => "#88ff88",
:endcolor => "#114411"
class LineItemsController < ApplicationController
# GET /line_items
# GET /line_items.xml
def index
@line_items = LineItem.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @line_items }
end
end
# GET /line_items/1
# GET /line_items/1.xml
def show
@line_item = LineItem.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @line_item }
end
end
# GET /line_items/new
# GET /line_items/new.xml
def new
@line_item = LineItem.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @line_item }
end
end
# GET /line_items/1/edit
def edit
@line_item = LineItem.find(params[:id])
end
# POST /line_items
# POST /line_items.xml
def create
@cart = find_or_create_cart
session[:counter]=0
product = Product.find(params[:product_id])
@line_item = @cart.add_product(product.id)
respond_to do |format|
if @line_item.save #redirect to sends you to cart page, not line_item again!
format.html { redirect_to(store_url) }
format.js { @current_item = @line_item }
format.xml { render :xml => @line_item, :status => :created, :location => @line_item }
else
format.html { render :action => "new" }
format.xml { render :xml => @line_item.errors, :status => :unprocessable_entity }
end
end
end
# PUT /line_items/1
# PUT /line_items/1.xml
def update
@line_item = LineItem.find(params[:id])
respond_to do |format|
if @line_item.update_attributes(params[:line_item])
format.html { redirect_to(@line_item, :notice => 'Line item was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @line_item.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /line_items/1
# DELETE /line_items/1.xml
def destroy
@line_item = LineItem.find(params[:id])
@line_item.destroy
respond_to do |format|
format.html { redirect_to(@line_item.cart, :notice => 'Line item was successfully deleted.') }
format.xml { head :ok }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment