Wednesday 27 March 2013

To Include Pagination in application

                                    You can use will_paginate gem to include pagination.



Example :


1) Include following in your gemfile and do 'bundle install'
 
'gem will_paginate'

2) Use code like below in controller if say your model name is Post



 @posts = Post.where(:published => true).paginate(:page => params[:page], :per_page => 5).order('id DESC')

      

3) In view file use <%= will_paginate @posts %>           

No comments:

Post a Comment