Ruby on rails 包装方法会导致方法未定义

Ruby on rails 包装方法会导致方法未定义,ruby-on-rails,ruby,authentication,Ruby On Rails,Ruby,Authentication,我有一个奇怪的问题:如果我跑 class ApplicationController < ActionController::Base http_basic_authenticate_with name: "test", password: "test" 我使用获取未定义的方法http\u basic\u authenticate\u。我哪里错了?http\u basic\u authenticate\u with是类方法,authenticate\u incoming是实例方法

我有一个奇怪的问题:如果我跑

class ApplicationController < ActionController::Base
    http_basic_authenticate_with name: "test", password: "test"

我使用
获取未定义的方法http\u basic\u authenticate\u。我哪里错了?

http\u basic\u authenticate\u with
是类方法,
authenticate\u incoming
是实例方法。您可以使用
执行
self.class.http\u basic\u authenticate\u,但在筛选
之前的
中这样做没有多大意义。你的目标是什么?也许我可以帮你想一想如何完成它。

http\u basic\u authenticate\u with
的源代码是

def http_basic_authenticate_with(options = {})
            before_filter(options.except(:name, :password, :realm)) do
              authenticate_or_request_with_http_basic(options[:realm] || "Application") do |name, password|
                name == options[:name] && password == options[:password]
              end
            end
          end
因此,您可以看到它在文件管理器之前实现了
。因此,您应该使用以下内容(您还可以存储一些
session
login数据;)

def http_basic_authenticate_with(options = {})
            before_filter(options.except(:name, :password, :realm)) do
              authenticate_or_request_with_http_basic(options[:realm] || "Application") do |name, password|
                name == options[:name] && password == options[:password]
              end
            end
          end
def authenticate_incoming
    authenticate_or_request_with_http_basic do |name, password|
          if name == 'hi' && password == 'ho'
            session[:logged_in] = true
            return true
          else
            return false
          end
        end
end