github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

adzap / make_resourceful_with_pagination

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 10
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

An evil-twin plugin for make_resourceful to add pagination — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

dup the class options to fix overwriting bug 
adzap (author)
Mon Nov 10 12:41:14 -0800 2008
commit  92bf2c3c1136b01e4dd161b667a642901f20478b
tree    84c0a202eb94e7ad9021aaf2c615f9fdd7ffd299
parent  40e42642933138ec2d020af41e975cdd5a2d7c98
make_resourceful_with_pagination /
name age
history
message
file MIT-LICENSE Loading commit data...
file README
file init.rb
directory lib/
README
make_resourceful_with_pagination
=====

A Rails evil-twin plugin (http://errtheblog.com/posts/67-evil-twin-plugin) for make_resourceful 
to add pagination in DRY way. You still need to install make_resourceful, this is not a fork.

Works with will_paginate and should work with paginating_find. 
Basically any paginator that acts on the model. This rules out classic pagination.


Example
=======

Adds pagination option to make_resourceful like so

  make_resourceful do
    actions :all
    paginate :per_page => 10
    
  end

Defaults to will_paginate but you can specify

  :pagination_method => :other_paginator

Also specify the :conditions as a string, hash, symbol for calling controller method or a proc

  make_resourceful do
    actions :all
    paginate :conditions => 'active = 1', :order => 'not_id'
    
  end

The current page defaults to calling a proc to work with will_paginate

  lambda { params[:page] }

but you can change it to a symbol of a method name which will be called before the pagination 
method is called.

To set global options update the class accessor in ApplicationController

  class ApplicationController < ActionController::Base

    resourceful_pagination_options.merge!(:per_page => 20)

    ...

OR for paginating_find

  class ApplicationController < ActionController::Base

    resourceful_pagination_options.merge!(:pagination_method => :find, :current_page => :page_options)

    def page_options
      { :current => params[:page], :size => 20 }
    end

    ...


Any options set other than :current_page and :pagination_method are passed to the pagination method
which should allow what ever customization on the finder you need.
    

Copyright (c) 2008 Adam Meehan (adam.meehan@gmail.com, http://duckpunching.com), released under the MIT license
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server