0

当尝试从不属于用户的资源请求 JSON 时,尽管我在下面写了验证,但 JSON 显示为空括号,但状态返回 200 OK。我需要更改什么以响应 401 状态:

    @requested_resource = params[:resource_id].to_i
    @users_resources = Resource.owned_by(@current_user.id).collect {|s| s.id}
    if @users_resources.include?(@requested_resource)

    else
      respond_to do |format|
        format.json { render :json => [], :status => :unauthorized }
        format.html { render :file => "public/401.html", :status => :unauthorized }
      end
    end

另外,我正在使用RABL ...

4

1 回答 1

1

让 RoR 为你玩游戏,redirect_torespond_to. 例如:

redirect_to "public/401.html", :alert => "Please authorize", :status => :unauthorized
于 2013-04-08T03:41:43.663 回答