Module: Controller::JsonApiConcern

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/controller/json_api_concern.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/concerns/controller/json_api_concern.rb', line 9

def index
  return super unless request.format == :json
  @collection = load_collection

  @collection = add_filter_to_scope(@collection) if (['only'] & params.keys).any?
  @collection = add_includes_to_scope(@collection) if included_associations.any?
  @collection = add_count_to_scope(@collection) if params[:count]
  respond_to do |format|
    format.json {  render json: @collection, include: included_associations  }
  end
end