Skip to content

Instantly share code, notes, and snippets.

@obrok
Created February 10, 2012 09:16
Show Gist options
  • Save obrok/1787974 to your computer and use it in GitHub Desktop.
Save obrok/1787974 to your computer and use it in GitHub Desktop.
def self.routes
Raptor.routes(self) do
index :responder => JSONResponder
end
end
class JSONResponder
def initialize(resource, action, params)
@resource = resource
@action = action
@presenter_name = params[:present]
end
def respond(record, injector)
injector.add_record(record)
presenter_class = @resource.send("#{@presenter_name}_presenter")
presenter = injector.call(presenter_class.method(:new))
Rack::Response.new(presenter.to_json, 200, {"Content-Type" => "application/json"})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment