Skip to content

Instantly share code, notes, and snippets.

@kulte
Created June 4, 2015 20:00
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 kulte/c1bb978043650cdee5c7 to your computer and use it in GitHub Desktop.
Save kulte/c1bb978043650cdee5c7 to your computer and use it in GitHub Desktop.
ams_endpoint.rb
class FoosController < ApplicationController
def index
@collection = Foo.all
render json: @collection, fields: params[:fields]
end
end
class FooSerializer < ActiveModel::Serializer
cache key: 'foo'
attributes(
:bar,
:baz,
:quz
)
end
GET /foos?fields=bar # => { data: [{ type: 'foos', id: 1, attributes: { bar: 'bar' } }, { type: 'foos', id: 2, attributes: { bar: 'bar' } }] }
GET /foos # => { data: [{ type: 'foos', id: 1, attributes: { bar: 'bar' } }, { type: 'foos', id: 2, attributes: { bar: 'bar' } }] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment