app/controllers/main.rb in sferik-merb-admin-0.3.4 vs app/controllers/main.rb in sferik-merb-admin-0.3.6
- old
+ new
@@ -16,24 +16,22 @@
options = {}
merge_filter(options)
merge_query(options)
merge_sort(options)
- if !MerbAdmin[:paginate] || params[:all]
+ if params[:all]
options = {
- :limit => 200,
+ :limit => MerbAdmin[:per_page] * 2,
}.merge(options)
@objects = @abstract_model.find_all(options).reverse
else
- # monkey patch pagination
- @abstract_model.model.class_eval('is_paginated') unless @abstract_model.model.respond_to?(:paginated)
@current_page = (params[:page] || 1).to_i
options = {
:page => @current_page,
:per_page => MerbAdmin[:per_page],
}.merge(options)
- @page_count, @objects = @abstract_model.model.paginated(options)
+ @page_count, @objects = @abstract_model.paginated(options)
options.delete(:page)
options.delete(:per_page)
options.delete(:offset)
options.delete(:limit)
end
@@ -155,11 +153,12 @@
conditions.unshift(condition_statement.join(' OR '))
options.merge!(:conditions => conditions) unless conditions == ['']
end
def merge_sort(options)
- return unless params[:sort]
- options.merge!(:order => [params[:sort].to_sym.send(params[:sort_reverse] ? :desc : :asc)])
+ sort = params[:sort] || "id"
+ order = params[:sort_reverse] == "true" ? :desc : :asc
+ options.merge!(:order => [sort.to_sym.send(order)])
end
def update_has_one_association(association, id)
model = MerbAdmin::AbstractModel.new(association[:child_model])
if object = model.find(id)