Skip to content

serializable_hash vs serializable_json when rendering json #392

@kapso

Description

@kapso

Whats the recommended way of using the serializer when rendering json in a controller? Is one better than the other?

class PostsController < ApplicationController
  def index
    posts = Post.joins(:comments)

    render json: PostSerializer.new(posts).serialized_json
    render json: PostSerializer.new(posts).serializable_hash # OR
    render json: PostSerializer.new(posts) # OR
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions