Module: AdministrateRansack::Searchable

Defined in:
lib/administrate_ransack/searchable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



23
24
25
# File 'lib/administrate_ransack/searchable.rb', line 23

def prepended(base)
  base.helper_method :sanitized_order_params
end

Instance Method Details

#sanitized_order_params(page, current_field_name) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/administrate_ransack/searchable.rb', line 14

def sanitized_order_params(page, current_field_name)
  collection_names = page.item_associations + [current_field_name]
  association_params = collection_names.map do |assoc_name|
    { assoc_name => %i[order direction page per_page] }
  end
  params.permit(:search, :id, :page, :per_page, association_params, q: {})
end

#scoped_resourceObject



7
8
9
10
11
# File 'lib/administrate_ransack/searchable.rb', line 7

def scoped_resource
  options = respond_to?(:ransack_options) ? ransack_options : {}
  @ransack_results = super.ransack(params[:q], **options)
  @ransack_results.result(distinct: true)
end