rss
twitter
    Find out what I'm doing, Follow Me :)

Ajax pagination with mislav's will_paginate

Installation of mislav's will_paginate.

In previous rails versions the PaginationHelper was in bilt but in later versions (Rails 2.0) it is deleted. There are two ways to install the will paginate.
  • use the gem(recommended)
  • install as Rails plugin using git

I have put that in the vender/gems folder.
Here is the process :

Gem Installation.

  1. Download the gem from the Git Hub :
  2. git clone git://github.com/mislav/will_paginate.git

  3. Put this in vender/gems folder.

  4. Put the following code in environment.rb file :

  5. config.gem "mislav-will_paginate", :version => "2.3.6", :lib => "will_paginate"
  6. Now in your controller write the code for pagination :


  7. def index
    @posts = Post.paginate(:all, :page => params[:page], :per_page => 6)
    respond_to do |format|
    format.html { }
    format.js {
    render :update do |page|
    page.replace_html 'all-posts', :partial => @posts
    page.replace_html 'pagination', :partial => 'pagination',
    :locals => {:collection => @posts}
    end
    }
    format.xml { render :xml => @posts }
    end
    end



    There will be two partials one for showing the posts and other for the pagination helper.

  8. The pagination partial will look like this : -
  9. pagination.html.erb :-

    <%= will_paginate collection, :remote => "true", :params => { :paginated => true } %>



  10. The index.rhtml file will be :


  11. index.html.erb :-



    <%= render :partial => @posts %>





1 comments:

Unknown said...
This comment has been removed by the author.