Resting Pug logo Resting Pug

Description

Renders json with a subject

Tip

Override this method to add more complicated logic of rendering.
Override Subject#subject_model_sym to change root attribute.
Override Params#permitted_fields_for_show to change shown attributes.

Used in

Use

Example

class BooksController < ApplicationController
  include RestingPug::Base

  private
  # Override a render_subject to render without a root object
  def render_subject
    render json: @subject.as_json(only: permitted_fields_for_show)
  end
end

Source code

# lib/resting_pug/render.rb

def render_subject
  render json: { subject_model_sym => @subject.as_json(only: permitted_fields_for_show) }
end
Find me on GitHub