Created
August 27, 2012 18:04
-
-
Save enricostano/3490918 to your computer and use it in GitHub Desktop.
create order CTRL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# POST /orders | |
# POST /orders.json | |
def create | |
@order = Order.new(params[:order]) | |
cart = session[:cart] | |
cart.each do | id, quantity | | |
item = Project.find_by_id(id) | |
@line_item = LineItem.new | |
@line_item.project = item | |
@line_item.quantity = quantity | |
@line_item.price = item.price | |
@line_item.order = @order | |
@line_item.save | |
end | |
@order.user = current_user | |
session.delete(:cart) | |
respond_to do |format| | |
if @order.save | |
format.html { redirect_to @order, notice: 'Order was successfully created.' } | |
format.json { render json: @order, status: :created, location: @order } | |
else | |
format.html { render action: "new" } | |
format.json { render json: @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