Created
June 30, 2016 16:30
-
-
Save MichaelCPell/c0ec7df49272aeb5ba0a65e7cdd45e29 to your computer and use it in GitHub Desktop.
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
if @order_item = @order.order_items.where(product_id: params[:product_id]) | |
@order_item.quantity = @order_item.quantity + 1 | |
@order_item.save | |
else | |
# Whatever | |
end |
What do you think?
Got it with:
def create
@order = current_order
if @order_item = @order.order_items.find_by(order_item_product)
@order_item.quantity = @order_item.quantity + @order_item.quantity
@order_item.update_attributes(order_item_quantity)
else
@order_item = @order.order_items.new(order_item_params)
@order.save
session[:order_id] = @order.id
end
end
def order_item_params
params.require(:order_item).permit(:quantity, :product_id, :book_id, :code, :product_ids => [])
end
def order_item_quantity
params.require(:order_item).permit(:quantity)
end
def order_item_product
params.require(:order_item).permit(:product_id)
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gives this error:
NoMethodError (undefined method
order_items' for nil:NilClass): app/controllers/order_items_controller.rb:4:in
create'