To add it to an application, the first obvious step is to install it if not already installed.
gem install will_paginate
Once available, add it to the config/environment.rb:
config.gem 'will_paginate', :version => '~> 2.3.16' (adjust for your version)
If you are using Bundler, add it to the Gemfile.
Next, add the paginate method to your controller result set for all records to be paginated:
@records = Record.find(:all)@records = @records.paginate(:page => params[:page], :per_page => 30)
Finally, add code to your view to display the navigation. I sometimes add it to both top and bottom, depending on how many records I am displaying.
<%= will_paginate @records, :style => 'color:blue' %>
No comments:
Post a Comment