authenticate_user!
的设计实现在哪里方法?
我一直在寻找它,但到目前为止还没有找到。
最佳答案
它位于lib/devise/controllers/helpers.rb
1并且是动态生成的(用户只是可能的后缀之一):
def self.define_helpers(mapping) #:nodoc:
mapping = mapping.name
class_eval <<-METHODS, __FILE__, __LINE__ + 1
def authenticate_#{mapping}!(opts={})
opts[:scope] = :#{mapping}
warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
end
def #{mapping}_signed_in?
!!current_#{mapping}
end
def current_#{mapping}
@current_#{mapping} ||= warden.authenticate(:scope => :#{mapping})
end
def #{mapping}_session
current_#{mapping} && warden.session(:#{mapping})
end
METHODS
ActiveSupport.on_load(:action_controller) do
helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session"
end
end
关于ruby-on-rails - "authenticate_user!"方法的设计实现在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9272272/