Over a million developers have joined DZone.

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')

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}