Skip to content

Instantly share code, notes, and snippets.

@greatseth
Created January 23, 2009 20:53
Show Gist options
  • Select an option

  • Save greatseth/51186 to your computer and use it in GitHub Desktop.

Select an option

Save greatseth/51186 to your computer and use it in GitHub Desktop.
def inject_status_in_response
yield
case request.format.to_sym
when :json
json = JSON.parse response.body
json["status"] = {
:code => response.status[/\d+/],
:message => @status_message
}
response.body = json.to_json
when :xml
xml = Builder::XmlMarkup.new response.body
xml.status do
xml.code response.status[/\d+/]
xml.message @status_message
end
response.body = xml
when :html
# ignore
else
raise NotImplementedError,
"need to implement status injection for format #{request.format.to_sym.inspect}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment