Мне не удалось заставить will_paginate работать, создав собственный метод поиска.
Я был почти успешным, но не совсем.
Вот что я пробовал:
В контроллере:
def refine_data
Result.paginate_refined_data :per_page => 5, :page => params[:page], :order => 'created_at DESC', :exclude =>"somestring"
end
В модели:
def find_refined_data(args)
exclude_string = args[:exclude];
new_results = do_some_work_and_exclude_records(@results,exclude_string)
end
will_paginate столкнулся с проблемой передачи мне дополнительного параметра: исключить, которого он не понял.
Самым простым решением для меня было создание собственного объекта WillPaginate :: Collection.
Итак, вот как моя теперь работает:
#The method name does not cause will_paginate to intercept and try to do its magic.
def new_find_refined_data(args)
exclude_string = args[:exclude];
new_results = do_some_work_and_exclude_records(@results,exclude_string)
@entries = WillPaginate::Collection.create(1, args[:per_page]) do |pager|
# inject the result array into the paginated collection:
pager.replace(new_results)
unless pager.total_entries
# the pager didn't manage to guess the total count, do it manually
pager.total_entries = new_results.length
end
end
end
Надеюсь, это поможет любому из парней, столкнувшихся с такой же проблемой: