Module: Sortable::InstanceMethods
- Defined in:
- lib/sortable.rb
Instance Method Summary collapse
-
#get_sorted_objects(params, options = {}) ⇒ Object
Users can also pass in optional conditions that are used by the finder method call.
-
#index ⇒ Object
default impl for listing a collection of objects.
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, ={}) objects = [:objects].nil? ? sortable_class : [:objects] include_rel = [:include_relations].nil? ? sortable_include_relations : [:include_relations] @headings = [:table_headings].nil? ? sortable_table_headings : [:table_headings] sort_map = [:sort_map].nil? ? sortable_sort_map : HashWithIndifferentAccess.new([:sort_map]) default_sort = [:default_sort].nil? ? sortable_default_sort : [:default_sort] conditions = [:conditions].nil? ? '' : [:conditions] search_array = [:search_array].nil? ? sortable_search_array : [:search_array] conditions = process_search(params, conditions, search_array) items_per_page = [:per_page].nil? ? sortable_per_page : [: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 |
#index ⇒ Object
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 |