app/controllers/apicasso/crud_controller.rb in apicasso-0.3.2 vs app/controllers/apicasso/crud_controller.rb in apicasso-0.3.3

- old
+ new

@@ -2,24 +2,24 @@ module Apicasso # Controller to consume read-only data to be used on client's frontend class CrudController < Apicasso::ApplicationController before_action :set_root_resource - before_action :set_object, except: %i[index schema create] + before_action :set_object, only: %i[show update destroy] before_action :set_nested_resource, only: %i[nested_index] before_action :set_records, only: %i[index nested_index] include Orderable # GET /:resource # Returns a paginated, ordered and filtered query based response. # Consider this - # To get all `Channel` sorted by ascending `name` and descending - # `updated_at`, filtered by the ones that have a `domain` that matches - # exactly `"domain.com"`, paginating records 42 per page and retrieving - # the page 42 of that collection. Usage: - # GET /sites?sort=+name,-updated_at&q[domain_eq]=domain.com&page=42&per_page=42 + # To get all `Channel` sorted by ascending `name` , filtered by + # the ones that have a `domain` that matches exactly `"domain.com"`, + # paginating records 42 per page and retrieving the page 42. + # Example: + # GET /sites?sort=+name,-updated_at&q[domain_eq]=domain.com&page=42&per_page=42 def index set_access_control_headers render json: index_json end @@ -49,22 +49,22 @@ def destroy authorize_for(action: :destroy, resource: resource.name.underscore.to_sym, object: @object) if @object.destroy - head :no_content, status: :ok + head :no_content, status: :ok else render json: @object.errors, status: :unprocessable_entity end end # GET /:resource/1/:nested_resource alias nested_index index # POST /:resource def create - @object = resource.new(resource_params) + @object = resource.new(object_params) authorize_for(action: :create, resource: resource.name.underscore.to_sym, object: @object) if @object.save render json: @object, status: :created, location: @object @@ -151,10 +151,10 @@ # The response for index action, which can be a pagination of a record collection # or a grouped count of attributes def index_json if params[:group].present? - @records.group(params[:group][:by].split(',')).send(params[:group][:calculate], params[:group][:fields]) + @records.group(params[:group][:by].split(',')).send(params[:group][:calculate], params[:group][:fields]||params[:group][:by].split(',')) else collection_response end end