-
Notifications
You must be signed in to change notification settings - Fork 335
Response Codes
nesquena edited this page Oct 22, 2012
·
4 revisions
https://github.com/nesquena/rabl/issues/88
class MyResponder < ActionController::Responder
def to_format
controller.response.status = :created if post?
super
end
endand then in the controller:
class ApplicationController < ActionController::Base
respond_to :json, :xml, :html
self.responder = MyResponder
endSetting controller.response.status is like a default value. It will be overridden by render/respond_with options, and by the super to_format for cases like has_errors?. You can add other default codes here as well, e.g.:
class KeydropResponder < ActionController::Responder
def to_format
if get? && !resource
controller.response.status = :not_found
elsif post?
controller.response.status = :created
end
super
end
end