0
を見つけることができません。テストAJAX:このコードは動作しますが、スペックは私がページにこのJavascriptを持つルート
<script type='text/javascript'>
function update_price(order_id, quantity) {
$.ajax({
beforeSend: function(xhr) {
xhr.setRequestHeader(
'X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
},
url: "/carts/" + <%= @cart.id %> + "/update_quantity", #you are missing 's' here is this a typo?
type: "POST",
data: {
"order_id" : order_id,
"quantity" : quantity }
});
}
</script>
それはユーザーのためだけで正常に動作します。一致するルートは次のようになります。
resources :carts, only: %i[update destroy index] do
member do
match 'update_quantity', to: 'carts#update_quantity', via: %i[get post]
end
end
私の仕様は次のようになります。
it 'updates the quantity' do
post "/cart/#{cart.id}/update_quantity", xhr: true, params: {
order_id: cart.orders.first.id,
quantity: 50
}
expect(response.status).to eq 200
end
しかし、私はこのエラーを取得しておいてください。それはユーザーのために働く、要するに
ActionController::UrlGenerationError:
No route matches {:action=>"/cart/2/update_quantity", :controller=>"carts", :order_id=>1, :quantity=>50}
が、スペックを渡すことができません。私は間違って何をしていますか?
は、私が手に使用します。
あなたは、レール5のアプリを持っているようなので、この1つは試す見えます'NoMethodError:super:スーパークラスメソッド' xhr 'for ... '。ちょっと変わった? –
@ CD-RUM 'xhr'はレール5で廃止されていますので、' xhr:true'オプションが使えます。私の答えを更新しました –