Skip to content

Instantly share code, notes, and snippets.

@UsamaAshraf
Created May 23, 2021 16:49
Show Gist options
  • Save UsamaAshraf/1e61cd388ad2b37d451077894982f27f to your computer and use it in GitHub Desktop.
Save UsamaAshraf/1e61cd388ad2b37d451077894982f27f to your computer and use it in GitHub Desktop.
class PostsController < ApplicationController
def index
posts = Post.all
render json: posts
end
end
class Post
belongs_to :author, class_name: 'User'
end
class PostSerializer < ActiveModel::Serializer
attributes :id, :title, :details
belongs_to :author
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment