Ruby on rails rails 4.2.6使用\u http\u验证\u或\u请求\u更新/放置/修补方法中的基本问题

Ruby on rails rails 4.2.6使用\u http\u验证\u或\u请求\u更新/放置/修补方法中的基本问题,ruby-on-rails,curl,csrf,curb,Ruby On Rails,Curl,Csrf,Curb,大家好,我在使用http\u basic进行身份验证或请求时遇到问题,代码如下: def authenticate puts "here 1" if authenticate_or_request_with_http_basic('Qontak') do |username, password| puts "here 2" @user = User.find_by(public_key: username, private_key: password) e

大家好,我在使用http\u basic进行身份验证或请求时遇到问题,代码如下:

def authenticate
  puts "here 1"
  if authenticate_or_request_with_http_basic('Qontak') do |username, password|
      puts "here 2"
      @user = User.find_by(public_key: username, private_key: password)
    end
  else
    puts "here 3"
    render json: {message: 'Unauthorized'}
  end
  puts "here 4"
end
当我调试更新方法时,控制台打印出:

here 1
here 4
然后出现如下错误日志:

Filter chain halted as :authenticate rendered or redirected
Completed 401 Unauthorized in 19ms (ActiveRecord: 2.2ms)
之后,我被重定向到
show route
,控制台成功地打印成这样

here 1
here 2
here 4

我想知道身份验证时,
put/patch/update
方法发生了什么?为什么失败但没有显示/获取路由?

尝试将未经授权的行更改为
返回呈现json…
仍然会给出相同的结果噢,对不起。我没有注意到这个错误。401 Unauthorized表示您的身份验证返回nil,因此无法进行身份验证。但我不知道这是否与您的问题相关(因为它可能应该记录在这里2)