Resting Pug logo Resting Pug

Description

Renders json with subjects

Tip

Override this method to add more complicated logic of rendering.
Override Subject#subject_model_sym_plural 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_subjects to render with 'items' as a root object
  def render_subjects
    render json: { items: @subjects.as_json(only: permitted_fields_for_show) }
  end
end

Source code

# lib/resting_pug/render.rb

def render_subjects
  render json: { subject_model_sym_plural => @subjects.as_json(only: permitted_fields_for_show) }
end
Find me on GitHub