Skip to content

Instantly share code, notes, and snippets.

@morgoth
Created February 11, 2011 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morgoth/822127 to your computer and use it in GitHub Desktop.
Save morgoth/822127 to your computer and use it in GitHub Desktop.
def respond_with(*resources, &block)
raise "In order to use respond_with, first you need to declare the formats your " <<
"controller responds to in the class level" if self.class.mimes_for_respond_to.empty?
if response = retrieve_response_from_mimes(&block)
options = resources.size == 1 ? {} : resources.extract_options!
resources = resources.size == 1 ? Array.wrap(resources.first) : resources
options.merge!(:default_response => response)
(options.delete(:responder) || self.class.responder).call(self, resources, options)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment