例如
200 => Found
403 => Not authorized
404 => Not found
我猜 Rails 3 已经具有此功能,因为您可以将哈希传递给render :status => :not_found
,我只是找不到以另一种方式执行此操作的方法。如果没有,有谁知道可以做到这一点的宝石?
irb(main):001:0> Rack::Utils::HTTP_STATUS_CODES[200]
=> "OK"
irb(main):002:0> Rack::Utils::HTTP_STATUS_CODES[403]
=> "Forbidden"
irb(main):003:0> Rack::Utils::HTTP_STATUS_CODES[404]
=> "Not Found"
或
irb(main):004:0> Rack::Utils.status_code(:ok)
=> 200
irb(main):005:0> Rack::Utils.status_code(:forbidden)
=> 403
irb(main):006:0> Rack::Utils.status_code(:not_found)
=> 404