Rails Error Codes
Contents |
I’m reposting it here for myself and whoever comes across rails http status code to symbol mapping it from a Google search. Thanks to this blog which
Rails Head
I have blatantly copied from. Read on for the complete list. Status Code Status Message Symbol rack::utils::symbol_to_status_code 1xx Informational 100 Continue :continue 101 Switching Protocols :switching_protocols 102 Processing :processing 2xx Success 200 OK :ok 201 Created :created 202 Accepted :accepted 203 Non-Authoritative
Rails Api Status Codes
Information :non_authoritative_information 204 No Content :no_content 205 Reset Content :reset_content 206 Partial Content :partial_content 207 Multi-Status :multi_status 226 IM Used :im_used 3xx Redirection 300 Multiple Choices :multiple_choices 301 Moved Permanently :moved_permanently 302 Found :found 303 See Other :see_other 304 Not Modified :not_modified 305 Use Proxy :use_proxy 307 Temporary Redirect :temporary_redirect 4xx rails unauthorized exception Client Error 400 Bad Request :bad_request 401 Unauthorized :unauthorized 402 Payment Required :payment_required 403 Forbidden :forbidden 404 Not Found :not_found 405 Method Not Allowed :method_not_allowed 406 Not Acceptable :not_acceptable 407 Proxy Authentication Required :proxy_authentication_required 408 Request Timeout :request_timeout 409 Conflict :conflict 410 Gone :gone 411 Length Required :length_required 412 Precondition Failed :precondition_failed 413 Request Entity Too Large :request_entity_too_large 414 Request-URI Too Long :request_uri_too_long 415 Unsupported Media Type :unsupported_media_type 416 Requested Range Not Satisfiable :requested_range_not_satisfiable 417 Expectation Failed :expectation_failed 422 Unprocessable Entity :unprocessable_entity 423 Locked :locked 424 Failed Dependency :failed_dependency 426 Upgrade Required :upgrade_required 5xx Server Error 500 Internal Server Error :internal_server_error 501 Not Implemented :not_implemented 502 Bad Gateway :bad_gateway 503 Service Unavailable :service_unavailable 504 Gateway Timeout :gateway_timeout 505 HTTP Version Not Supported :http_version_not_supported 507 Insufficient Storage :insufficient_storage 510 Not Extended :not_extended Enjoy. Written by Bill Patrianakos Published Oct 13th, 2013 Web development Tweet « Rails Tricky Error: No implicit conversion from symbol to integer API Se
a GitHub account Sign in Create a gist now Instantly share code,
Rails Render Json
notes, and snippets. Star 34 Fork 22 mlanett/rails http status
Rails Unprocessable Entity
codes Last active Sep 30, 2016 Embed What would you like to do? Embed rails render json status Embed this gist in your website. Embed Share Copy sharable URL for this gist. Share Clone via HTTPS Clone with Git or checkout with http://billpatrianakos.me/blog/2013/10/13/list-of-rails-status-code-symbols SVN using the repository's web address. HTTPS Learn more about clone URLs Download ZIP Code Revisions 6 Stars 34 Forks 22 HTTP status code symbols for Rails Raw rails http status codes HTTP status code symbols for Rails Thanks to Cody Fauser for this list of HTTP https://gist.github.com/mlanett/a31c340b132ddefa9cca responce codes and their Ruby on Rails symbol mappings. Status Code Symbol 1xx Informational 100 :continue 101 :switching_protocols 102 :processing 2xx Success 200 :ok 201 :created 202 :accepted 203 :non_authoritative_information 204 :no_content 205 :reset_content 206 :partial_content 207 :multi_status 226 :im_used 3xx Redirection 300 :multiple_choices 301 :moved_permanently 302 :found 303 :see_other 304 :not_modified 305 :use_proxy 307 :temporary_redirect 4xx Client Error 400 :bad_request 401 :unauthorized 402 :payment_required 403 :forbidden 404 :not_found 405 :method_not_allowed 406 :not_acceptable 407 :proxy_authentication_required 408 :request_timeout 409 :conflict 410 :gone 411 :length_required 412 :precondition_failed 413 :request_entity_too_large 414 :request_uri_too_long 415 :unsupported_media_type 416 :requested_range_not_satisfiable 417 :expectation_failed 422 :unprocessable_entity 423 :locked 424 :failed_dependency 426 :upgrade_required 5xx Server Error 500 :internal_server_error 501 :not_implemented 502 :bad_gateway 503 :service_unavailable 504 :gateway_timeout 505 :http_version_not_supported 507 :insufficient_storage 510 :not_extended juanpastas commented Aug 4, 2016 Is not there a map inside Rails? juanpastas commented Aug 4, 2016 •
helpers. A minimal implementation could be: class Person # Required dependency for ActiveModel::Errors extend ActiveModel::Naming def initialize @errors = ActiveModel::Errors.new(self) end attr_accessor :name attr_reader :errors def http://api.rubyonrails.org/classes/ActiveModel/Errors.html validate! errors.add(:name, :blank, message: "cannot be nil") if name.nil? end # The following methods are needed to be minimally implemented def read_attribute_for_validation(attr) send(attr) end def self.human_attribute_name(attr, options = {}) attr end def self.lookup_ancestors [self] end end The last three methods are required in your object for Errors to be able to generate error messages correctly and status code also handle multiple languages. Of course, if you extend your object with ActiveModel::Translation you will not need to implement the last two. Likewise, using ActiveModel::Validations will handle the validation related methods for you. The above allows you to do: person = Person.new person.validate! # => ["cannot be nil"] person.errors.full_messages # => ["name cannot be nil"] # etc.. rails render json Methods # [], []= A add, add_on_blank, add_on_empty, added?, as_json B blank? C clear, count D delete E each, empty? F full_message, full_messages, full_messages_for G generate_message, get H has_key? I include? K key?, keys M marshal_dump, marshal_load N new S set, size T to_a, to_hash, to_xml V values Included Modules Enumerable Constants CALLBACKS_OPTIONS = [:if, :unless, :on, :allow_nil, :allow_blank, :strict] MESSAGE_OPTIONS = [:message] Attributes [R] details [R] messages Class Public methods new(base) Link Pass in the instance of the object that is using the errors object. class Person def initialize @errors = ActiveModel::Errors.new(self) end end Source: show | on GitHub # File activemodel/lib/active_model/errors.rb, line 72 def initialize(base) @base = base @messages = apply_default_array({}) @details = apply_default_array({}) end Instance Public methods [](attribute) Link When passed a symbol or a name of a method, returns an array of errors for the method. person.errors[:name] # => ["cannot be nil"] person.errors['name'] # => ["cannot be nil"] Note that, if you try to get errors of an attribute which has no