Sha256: 6cce962ba2a24f675e07bef7d4021b648f810453546f59aa179d44740bfb33c6
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
module PagedScopes module Controller def get_page_for(collection_name, options = {}) callback_method = "get_page_for_#{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}") collection.per_page = options[:per_page] if options[:per_page] collection.page_name = options[:name] if options[:name] page = collection.pages.from_params!(params) || (object && collection.pages.find_by_object(object)) || collection.pages.first page.paginator.set_path { |pg| send(options[:path], pg) } if options[:path] instance_variable_set("@#{collection.pages.name.underscore}", page) end protected callback_method before_filter callback_method, options.except(:per_page, :name, :path) end end end if defined? ActionController::Base ActionController::Base.extend PagedScopes::Controller ActionController::Base.rescue_responses.update('PagedScopes::PageNotFound' => :not_found) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mholling-paged_scopes-0.0.3 | lib/paged_scopes/controller.rb |