Skip to content

Instantly share code, notes, and snippets.

@joshsmith
Created June 5, 2014 17:56
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 joshsmith/dec2d44907956305003a to your computer and use it in GitHub Desktop.
Save joshsmith/dec2d44907956305003a to your computer and use it in GitHub Desktop.
Serializers
class RecipeSerializer < ActiveModel::Serializer
embed :ids, include: true
has_many :steps
attributes :id, :title
end
class RecipesController < ApplicationController
def index
@recipes = Recipe.all
render json: @recipes, each_serializer: ShortRecipeSerializer
end
def show
@recipe = Recipe.find(params[:id])
render json: @recipe
end
end
class ShortRecipeSerializer < ActiveModel::Serializer
attributes :id, :title
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment