Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

List HTTP Status Codes In Rails

DZone's Guide to

List HTTP Status Codes In Rails

·
Free Resource
If you follow the Rails way of RESTful controllers you should familiarize yourself with all the return status codes available in the HTTP protocol.

The following is a handy list, like "rake routes", for listing out all the HTTP codes that you can return in your controller logic.


desc 'Lists ActionController::StatusCodes::STATUS_CODES like routes'
task :status_codes => :environment do
  puts "Status - Name"
  ActionController::StatusCodes::STATUS_CODES.to_a.sort.each { |code, message| 
    puts "#{code}    - #{message.gsub(/ /, "").underscore.to_sym}"
  } if ActionController::StatusCodes.constants.include?('STATUS_CODES')
end
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}