rails 4.2.6 update / put / patch方法中的authenticate_or_request_with_http_basic问题

时间:2017-02-28 10:15:36

标签: ruby-on-rails curl csrf curb

大家好我authenticate_or_request_with_http_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方法发生了什么?为什么它失败但没有显示/获取路线?

0 个答案:

没有答案