Module: Gridy::Controller

Extended by:
ActiveSupport::Concern
Defined in:
lib/gridy/controller.rb,
lib/gridy/controller/actions.rb

Defined Under Namespace

Modules: Actions

Instance Method Summary collapse

Instance Method Details

#gridy_collection(collection, options = {}) ⇒ Object



44
45
46
47
48
# File 'lib/gridy/controller.rb', line 44

def gridy_collection(collection, options = {})
  @ransack = gridy_query(collection, options)
  @pagy, @records = pagy(@ransack.result(distinct: true), items: options[:items] || 20)
  instance_variable_set("@#{resource_name.pluralize.underscore}", @records)
end

#gridy_query(collection, options = {}) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/gridy/controller.rb', line 50

def gridy_query(collection, options = {})
  query = {}

  query[self.class.resource.searchable_key] = options[:q] if searchable?
  query[:s] = options[:sort] if sortable?

  collection.ransack(query)
end