在我的 Rails 7 應用程式中,我有自定義的 two_factor_authentication。現在我只想在開發和測驗環境中啟用這個 2fa。
class ApplicationController < ActionController::Base
before_action :check_two_factor_authentication, except: :check_authentication
private
def check_two_factor_authentication
return true unless session[:challenge_id]
redirect_to two_factor_path
end
我不知道是什么,check_authentication因為在整個應用程式中沒有這樣的方法——我猜它來自 Devise gem。
如何僅在開發環境中設定之前的操作?
uj5u.com熱心網友回復:
你有沒有嘗試過
if %w(development test).include?(Rails.env)
before_action :check_two_factor_authentication, except: :check_authentication
end
?
uj5u.com熱心網友回復:
您可以使用Rails.env.development?(or Rails.env.production?) 來測驗您所處的環境。
if Rails.env.development?
before_action :check_two_factor_authentication, except: :check_authentication
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/534556.html
上一篇:計算總價(商品數量*商品價格)
下一篇:更新后的Rails模型獲取更改
