Skip to content

Instantly share code, notes, and snippets.

@beydogan
Created June 18, 2013 13:35
Show Gist options
  • Save beydogan/5805406 to your computer and use it in GitHub Desktop.
Save beydogan/5805406 to your computer and use it in GitHub Desktop.
order create method
# POST /orders
# POST /orders.json
def create
@order = current_user.orders.new(params[:order])
@order.add_line_items_from_cart(current_cart)
@order.payment.amount = @order.total_price
@order.payment.save
respond_to do |format|
if @order.save
Cart.destroy(session[:cart_id])
session[:cart_id] = nil
format.html { redirect_to(@order, :notice =>
'Thank you for your order.' ) }
format.xml { render :xml => @order, :status => :created,
:location => @order }
else
format.html { render :action => "new" }
format.xml { render :xml => @order.errors,
:status => :unprocessable_entity }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment