Skip to content

Instantly share code, notes, and snippets.

@foucist
Forked from anonymous/user_serializer
Last active December 28, 2015 10:09
Show Gist options
  • Save foucist/7483781 to your computer and use it in GitHub Desktop.
Save foucist/7483781 to your computer and use it in GitHub Desktop.
class UserSerializer < ActiveModel::Serializer
attributes :id, :name, :phone, :email, :balance, :children, :balance
def attributes
data = super
data[:children] = User.find(data[:id]).subordinates.any?
data
end
end
if request.format.json? && params[:id] != nil && have_permissions?(User.find(params[:id]))
render json: @subusers, root: false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment