Sunday 2nd November 2008
by Sajith M.ROld rails has a buitl in pagination option. For example is you have to paginate @user, which is a model object for the table user
def user_list
@user_pages,@users=paginate(:users,:order=>’name’)
end
But in new version of rails, they removed the pagination option. So you need to install a plugin , which name is will_paginate
You can install this plugin using gem
gem install will_paginate
After the installation you have to add require “will_paginate” in config/environment.rb (at bottom)
You have to restart your ruby server after that.
In the controller area use:
def index
@poems = Poem.paginate :page => params[:page],
rder => 'created_at DESC'
end
and in the template page use
<%= will_paginate @poems, :container => false %>
Tags: code, pagination, rail, ruby
Thnks it worked well for me.
pls NOTE one thing add require “will_paginate” in config/environment.rb (at bottom). ie after the ‘end’. Be careful !!