4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/paged_scopes/controller.rb', line 4
def paginate(*args)
options = args.
raise ArgumentError, "can't paginate multiple collections with one call" if args.many?
collection_name = args.first || default_collection_name
callback_method = "paginate_#{collection_name}"
define_method callback_method do
collection = instance_variable_get("@#{collection_name.to_s.pluralize}")
raise RuntimeError, "no @#{collection_name.to_s.pluralize} collection was set" unless collection
object = instance_variable_get("@#{collection_name.to_s.singularize}")
page = page_for(collection, object, options)
instance_variable_set("@#{collection.pages.name.underscore}", page)
end
protected callback_method
before_filter callback_method, options.except(:per_page, :name, :path)
end
|