List HTTP Status Codes In Rails
Join the DZone community and get the full member experience.
Join For FreeIf 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
Opinions expressed by DZone contributors are their own.
Comments