共通のヘルパーはどこに作るのがベストなのか

環境

Rails 5.2

内容

Viewで呼び出すヘルパーを作成する場所は、どこかベストなのでしょうか。
2通りのやり方があることを知り、混乱しております。

1つ目のやり方は、下記のコードで、controllers/helpers/application_helper.rbの中に書く方法です。
個人的にはこれがベストだと思っていました。

module ApplicationHelper def current_user @current_user ||= User.find(id: session[:user_id]) end end

2つ目のやり方は、controllers/application_controller.rbの中に書く方法です。こんなやり方があるんだと、後から知り、混乱してしまいました。アドバイスをお願いします。

class ApplicationController < ActionController::Base helper_method :current_user def current_user @current_user ||= User.find(id: session[:user_id]) end end

コメントを投稿

0 コメント