質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

967閲覧

<エラー>NoMethodError in Customers::CartItemsController#destroy_all

kan1m1souma

総合スコア2

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2021/12/09 03:12

<エラー>NoMethodError in Customers::CartItemsController#destroy_all

Ruby on Rails初心者です。ECサイトを作成中、「カートの中に入れた商品を全て空にする」として「destryoi_all」、空にした際に再度カートアイテム一覧ページに遷移したいのですが、カートを空にするボタンを押した際に、NoMethodErrorが出ています。
※初めてこの場を使うので、慣れない箇所があるかもしれませんがご容赦ください。

発生している問題・エラーメッセージ

NoMethodError in Customers::CartItemsController#destroy_all undefined method `refere' for #<ActionDispatch::Request:0x00007f21dd3e3c20> Did you mean? referer referrer

CartItemsController

class Customers::CartItemsController < ApplicationController before_action :move_to_signed_in def index @cart_items = CartItem.all @customer_cart_items = CartItem.where(customer_id: current_customer.id) end def create @cart_item = CartItem.new(cart_item_params) @item = @cart_item.item if @cart_item.save redirect_to cart_items_path else redirect_to item_path(@item) end end def update @cart_item = CartItem.find(params[:id]) if @cart_item.update(cart_item_params) redirect_to request.referer end end def destroy @cart_item = CartItem.find(params[:id]) if cart_items.destroy redirect_to request.refere end end def destroy_all if CartItem.destroy_all redirect_to request.refere end end def move_to_signed_in unless customer_signed_in? redirect_to '/customers/sign_in' end end private def cart_item_params params.require(:cart_item).permit(:customer_id, :item_id, :pieces) end end

Views(show画面)

<h4>ショッピングカート</h4> <% if @customer_cart_items.exists? %> <%= link_to "カートを空にする", cart_items_destroy_all_cart_items_path, method: :delete %>

Route

resources :cart_items, only:[:index, :create, :update, :destroy]do collection do delete 'cart_items/destroy_all' => 'cart_items#destroy_all' end end

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

解決できました。コントローラーを見直したところパスの名前が間違っていたのが原因でした。

投稿2021/12/09 04:11

kan1m1souma

総合スコア2

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問