Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 611
user545139 Avatar asked May 16 '11 04:05

user545139


1 Answers

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
like image 198
Vasiliy Ermolovich Avatar answered Nov 15 '22 08:11

Vasiliy Ermolovich