Method: BetterController::ResourcesController#index

Defined in:
lib/better_controller/resources_controller.rb

#indexObject

Index action to list all resources



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/better_controller/resources_controller.rb', line 20

def index
  execute_action do
    collection = resource_collection_resolver

    # Apply pagination if enabled
    if self.class.pagination_options[:enabled] && collection.respond_to?(:page)
      @resource_collection = paginate(collection,
                                      page:     params[:page],
                                      per_page: params[:per_page] || self.class.pagination_options[:per_page])
    else
      @resource_collection = collection
    end

    data = serialize_resource(@resource_collection, index_serializer)
    respond_with_success(data, options: { meta: meta })
  end
end