?
Solved

Ruby select number of records to view

Posted on 2011-04-21
1
Medium Priority
?
404 Views
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?
0
Comment
Question by:lcor
1 Comment
 
LVL 6

Accepted Solution

by:
eksatx earned 2000 total points
ID: 35443480
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])
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
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…
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

840 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