开发者

Is there an method in Rails3 / ruby gem, which maps status codes to messages?

Such as

200 => Found
403 => Not authorized
404 => Not found

I'm guessing Rails 3 already has this functionality as you can pass a hash to render :status => :not_found, I just can't find the method to do it the other way. If not does anyone know of a gem which can开发者_开发百科 do this?


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"

or

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜