我有一个非常标准的身份验证方法
private def authenticate_user @current_user = User.find_by_authentication_token(params[:token]) unless @current_user error = { :error => "Invalid token." } respond_with(error,:status => 401 ) end end
我正在调用API以确保身份验证失败.
我收到一个错误说明
ArgumentError (Nil location provided. Can't build URI.): app/controllers/api/v1/base_controller.rb:13:in `authenticate_user'
我究竟做错了什么?
解决方法
根据您的错误的特定风格,我猜测“authenticate_user”被称为“创建”操作的一部分.
如果是这种情况,我相信我提供的答案here也会对您有所帮助.
但是,假设这是创建经过身份验证的会话的一部分,这意味着新创建的“资源”没有实际位置,我将为响应位置提供nil,如:
... respond_with(error,:status => 401,:location => nil) ...
一旦你看到链接的答案,这将更有意义.如果它仍然没有意义,我将很乐意澄清.