Last active
August 29, 2015 14:14
-
-
Save hauntedhost/548d5ee19f7f72b4d28c to your computer and use it in GitHub Desktop.
active_model_serializers condition sideloading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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