看起来ActionController::StatusCodes
已经从Rails 3中删除了
200 => :ok
404 => :not_found
500 => :internal_server_error
查看更多代码:
http://apidock.com/rails/ActionController/Base/render 254 -列表- -状态-编码-和-他们的符号
我在哪里可以找到这些在Rails 3?
Ruby on Rails使用Rack。状态码在Rack::Utils:
中定义。HTTP_STATUS_CODES = {
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
200 => 'OK',
201 => 'Created',
...
}
然后这些被用来创建符号(即:switching_protocols
):
SYMBOL_TO_STATUS_CODE = Hash[*HTTP_STATUS_CODES.map { |code, message|
[message.downcase.gsub(/s|-/, '_').to_sym, code]
}.flatten]
全部代码可在此浏览
似乎错误代码驻留在action_dispatch/middleware/show_exceptions.rb
中,其中的符号被映射到实际的异常:
'ActionController::RoutingError' => :not_found,
'AbstractController::ActionNotFound' => :not_found,
'ActiveRecord::RecordNotFound' => :not_found,
'ActiveRecord::StaleObjectError' => :conflict,
'ActiveRecord::RecordInvalid' => :unprocessable_entity,
'ActiveRecord::RecordNotSaved' => :unprocessable_entity,
'ActionController::MethodNotAllowed' => :method_not_allowed,
'ActionController::NotImplemented' => :not_implemented,
'ActionController::InvalidAuthenticityToken' => :unprocessable_entity
然而,100 - 400范围的映射从Rails中消失了,可能是因为它们已经存在于Rack中。