Created
January 23, 2009 20:53
-
-
Save greatseth/51186 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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