Skip to content

Instantly share code, notes, and snippets.

@MikeSilvis
Created September 23, 2012 15:25
Show Gist options
  • Save MikeSilvis/3772029 to your computer and use it in GitHub Desktop.
Save MikeSilvis/3772029 to your computer and use it in GitHub Desktop.
class PhotoSerializer < ActiveModel::Serializer
attributes :id, :created_at, :photo_url_thumb, :photo_url_large
# Only include these if it is coming from the show action
has_many :likes
has_many :tags
has_many :comments
end
class PhotosController < ApplicationController
def index
render json: Photo.all
end
def show
render json: Photo.where(id: params[:id]).includes(:comments, :tags, :likes).first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment