Module: Snaptable::Constructor::Collection

Included in:
BaseTable
Defined in:
lib/snaptable/constructor/collection.rb

Instance Method Summary collapse

Instance Method Details

#collectionObject



5
6
7
# File 'lib/snaptable/constructor/collection.rb', line 5

def collection
  @collection.includes(belongs_to_associations)
end

#filter(collection) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/snaptable/constructor/collection.rb', line 13

def filter(collection)
  if options[:search] == true && !params[:query].blank?
    collection.joins(search_associations).where(query, query: "%#{params[:query]}%", id: params[:query].to_i)
  else
    collection
  end
end

#recordsObject



9
10
11
# File 'lib/snaptable/constructor/collection.rb', line 9

def records
  @records ||= filter(collection).paginate(page: params[:page], per_page: 30).order(sort_column + " " + sort_direction)
end