Skip to content

Instantly share code, notes, and snippets.

@pdobb
pdobb / gist:d4f0b2375bdc210d24e6
Last active August 29, 2015 14:21
Custom API Responder
# app/models/api_v2_responder.rb
# This approach was heavily inspired by
# http://josephhsu.com/post/32746478033/rails-responders-api-versioning.
# Overriding the #to_json method wasn't right though, as it removed half of the
# awesome functionality of respond_with.
#
# @see https://github.com/rails/rails/blob/v3.2.17/actionpack/lib/action_controller/metal/responder.rb
class ApiV2Responder < ActionController::Responder
# Override the original `#display` method to wrap the passed in resource in
# the correspondingly named Presenter.