我有一个辅助模块ModelHelper。我要使用user_signed_in吗?助手模块中的方法。但是它显示错误。如何在帮助文件中调用此方法。
我认为您可以使用current_user.present?
无论如何,Rails助手非常丑陋,我建议不要使用它]
user_signed_in?
模块中定义的Devise::Controllers::Helpers::ClassModule
方法。长话短说,它只是检查scope
是否在warden
中进行了身份验证。因此,您可以尝试在没有Devise
帮助者的情况下进行检查
def #{mapping}_signed_in?
!!current_#{mapping}
end
def current_#{mapping}
@current_#{mapping} ||= warden.authenticate(scope: :#{mapping})
end