Skip to content

Instantly share code, notes, and snippets.

@hauntedhost
Last active August 29, 2015 14:14
Show Gist options
  • Save hauntedhost/548d5ee19f7f72b4d28c to your computer and use it in GitHub Desktop.
Save hauntedhost/548d5ee19f7f72b4d28c to your computer and use it in GitHub Desktop.
active_model_serializers condition sideloading
class CatsController < ApplicationController
def index
render json: Cat.all, simple: params[:simple], status: :ok
end
end
class CatSerializer < ActiveModel::Serializer
attributes :id, :age, :name
has_many :birds
has_many :squirrels
def include_birds?
!options[:simple]
end
def include_squirrels?
!options[:simple]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment