これが私がしたことです:
にapp/controllers/application_controller.rb
、次の行を追加します。
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :authenticate_user!
# ...
end
これにより、アクションの前に強制的authenticate_user!
に実行されます。
認証を必要としないアクション/コントローラーがある場合は、コントローラー ファイルに次の行を追加できます。
class StaticPagesController < ApplicationController
prepend_before_filter :require_no_authentication
# ...
end
この関数は、認証を必要としないアクションのリストを含む、require_no_authentication
オプションのパラメーター という名前の配列も受け取ります。only
nb これが高度なネクロマンシーであることは知っていますが、質問には答えがなく、正しい答えを探すのにかなりの時間を費やしました。