Sha256: ae3847b72896329a73f39de30ac059e31aa32909d3930c202134b2b0305723ad

Contents?: true

Size: 721 Bytes

Versions: 7

Compression:

Stored size: 721 Bytes

Contents

module Controller
  module RansackConcern
    private

    # def collection_scope
    #   @q = collection_scope_with_search_scopes(resource_class).ransack(params[:q])
    #   @q.result(distinct: true)
    # end

    def load_collection
      @q = collection_scope_with_search_scopes(collection_scope).ransack(params[:q])
      @q.result(distinct: true)
    end

    def collection_scope_with_search_scopes(base_scope)
      final_scope = base_scope
      search_scopes.each do |scope|
        final_scope = final_scope.send(scope)
      end
      final_scope
    end

    def search_scopes
      return [] unless params.key?(:q) && params[:q].key?(:scopes)
      params[:q][:scopes].keys - ['unscoped']
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
itsf_backend-5.0.0.pre app/controllers/concerns/controller/ransack_concern.rb
itsf_backend-4.2.3 app/controllers/concerns/controller/ransack_concern.rb
itsf_backend-4.2.2 app/controllers/concerns/controller/ransack_concern.rb
itsf_backend-4.2.1 app/controllers/concerns/controller/ransack_concern.rb
itsf_backend-4.2.0 app/controllers/concerns/controller/ransack_concern.rb
itsf_backend-4.0.1 app/controllers/concerns/controller/ransack_concern.rb
itsf_backend-4.0.0 app/controllers/concerns/controller/ransack_concern.rb