class RankingController < ApplicationController layout 'review_site' before_action :ranking def ranking product_ids = Review.group(:product_id).order('count_product_id DESC').limit(5).count(:product_id).keys end end``` というコードがあります。 疑問なんですがこのbefore_actionは必要ないのではないでしょうか。 自分の見解↓ before_actionによって「コントローラのアクションが実行される前にそのrankingメソッドを実行することができる」 よって順番的にrankingというメソッドが実行される→ranking_contrlloerのrankingアクションが実行される→review_site.html.erbが呼ばれる アクションとは→コントローラに存在するインスタンスメソッド しかしそもそもrankingというメソッド一つしかこのcontrollerの中にはないのでbefore_actionで指定しなくても必然的にそうなるのでは???
コード部分を ``` で囲っていただけますか。(質問を新規作成したときにサンプルが出てきます)
回答1件
あなたの回答
tips
プレビュー