Ruby select number of records to view

Posted on 2011-04-21
Last Modified: 2012-05-11
Using Ruby on Rails 1.8

I need to filter the number of records being displayed on a page.  A select box gives several choices of the number to be displayed.  Once the value is chosen, the page will be updated.

How do I implement this using ruby on rails?
Question by:lcor
    1 Comment
    LVL 6

    Accepted Solution

    I recommend using one of the pagination gems

    (will_paginate is still very popular).

    It lets you put something like this in your controller:

    @things = Thing.paginate(:all, :page => params[:page],

    :per_page => 10)

    Now, you want to have the user select how many records to

    show per page.  Therefore, you should add a select to your

    view that sets a parameter called per_page.

    You then just need to change the line in your controller

    to this:

    @things = Thing.paginate(:all, :page => params[:page],

    :per_page => params[:per_page])

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to…
    Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now