Skip to content

Instantly share code, notes, and snippets.

@rocodev-tech
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save rocodev-tech/6b340e2ce5877fe5b9da to your computer and use it in GitHub Desktop.

Select an option

Save rocodev-tech/6b340e2ce5877fe5b9da to your computer and use it in GitHub Desktop.
app/controllers/orders_controller.rb
class OrdersController < ApplicationController
before_action :authenticate_user!
def create
@order = current_user.orders.build(order_params)
if @order.save
@order.build_item_cache_from_cart(current_cart)
@order.calculate_total!(current_cart)
redirect_to root_path
else
render "carts/checkout"
end
end
private
def order_params
params.require(:order).permit(:info_attributes => [:billing_name, :billing_address,:shipping_name, :shipping_address] )
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment