{"comment":{"url":"https://api.github.com/repos/takeroyasuhara/ec_app/comments/13254850","html_url":"https://github.com/takeroyasuhara/ec_app/commit/67ea521f43b540accefeff3c7b0142de5937c3b0#commitcomment-13254850","id":13254850,"user":{"login":"takeroyasuhara","id":13011597,"avatar_url":"https://avatars.githubusercontent.com/u/13011597?v=3","gravatar_id":"","url":"https://api.github.com/users/takeroyasuhara","html_url":"https://github.com/takeroyasuhara","followers_url":"https://api.github.com/users/takeroyasuhara/followers","following_url":"https://api.github.com/users/takeroyasuhara/following{/other_user}","gists_url":"https://api.github.com/users/takeroyasuhara/gists{/gist_id}","starred_url":"https://api.github.com/users/takeroyasuhara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takeroyasuhara/subscriptions","organizations_url":"https://api.github.com/users/takeroyasuhara/orgs","repos_url":"https://api.github.com/users/takeroyasuhara/repos","events_url":"https://api.github.com/users/takeroyasuhara/events{/privacy}","received_events_url":"https://api.github.com/users/takeroyasuhara/received_events","type":"User","site_admin":false},"position":6,"line":6,"path":"app/controllers/cart_items_controller.rb","commit_id":"67ea521f43b540accefeff3c7b0142de5937c3b0","created_at":"2015-09-16T07:24:56Z","updated_at":"2015-09-16T07:24:56Z","body":"ありがとうございます、このように変更いたしました。\r\n```Ruby\r\ndef create\r\n    product = Product.find(params[:cart_item][:product_id])\r\n    asking_quantity = params[:cart_item][:asking_quantity].to_i\r\n    cart_item = current_user.cart_items.find_or_initialize_by(product_id: product.id)\r\n    cart_item.asking_quantity += asking_quantity\r\n    cart_item.asking_price = product.price\r\n    cart_item.possible_quantity = cart_item.asking_quantity\r\n    if (cart_item.asking_quantity <= product.stock_quantity) && cart_item.save\r\n      flash[:success] = \"#{product.title}をカートに追加しました\"\r\n    else\r\n      flash[:danger] = \"#{product.title}は在庫数が不足しています\"\r\n    end\r\n    redirect_to cart_items_path\r\n  end\r\n```"}}