Module: Sortable::InstanceMethods

Defined in:
lib/sortable.rb

Instance Method Summary collapse

Instance Method Details

#get_sorted_objects(params, options = {}) ⇒ Object

Users can also pass in optional conditions that are used by the finder method call. For example if only wanted to show the items that had a certain status value you could pass in a condition ‘mytable.status == 300’ for example as the conditions parameter and when the finder is called the sortable table will only display objects that meet those conditions. Additionally you can paginate and sort the objects that are returned and apply the conditions to them.



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/sortable.rb', line 180

def get_sorted_objects(params, options={})                           
  objects = options[:objects].nil? ? sortable_class : options[:objects]
  include_rel = options[:include_relations].nil? ? sortable_include_relations : options[:include_relations]
  @headings = options[:table_headings].nil? ? sortable_table_headings : options[:table_headings]
  sort_map = options[:sort_map].nil? ? sortable_sort_map : HashWithIndifferentAccess.new(options[:sort_map])
  default_sort = options[:default_sort].nil? ? sortable_default_sort : options[:default_sort]
  conditions = options[:conditions].nil? ? '' : options[:conditions]
  search_array = options[:search_array].nil? ? sortable_search_array : options[:search_array]
  
  conditions = process_search(params, conditions, search_array)
  items_per_page = options[:per_page].nil? ? sortable_per_page : options[:per_page]
 
  @sort_map = sort_map
  sort = process_sort(params, sort_map, default_sort)
  page = params[:page]
  page ||= 1
  # fetch the objects, paginated and sorted as desired along with any extra filtering conditions
  get_paginated_objects(objects, sort, include_rel, conditions, page, items_per_page)
end

#indexObject

default impl for listing a collection of objects. Override this action in your controller to fetch objects differently and/or to render a different template.



171
172
173
174
# File 'lib/sortable.rb', line 171

def index
  get_sorted_objects(params)  
  render :template => 'sortable/index'
end