Forgive me, guys; I'm still a complete RoR newbie.
I'm trying to use the will_paginate gem to add pagination to search results in my Rails app. Thus far it's been working great. However, I've hit a roadblock.
I have a "products" table with thousands of records that I want to be completely browsable. This is easy in the most basic scenario. I've got this in my controller:
page = params[:page] || 1
@products = Product.paginate :page => page, :order => 'symbol'
What I want to do is add a parameter, "letter," so that only products whose symbols start with the given letter are paginated and displayed.
This is what I tried:
letter = params[:letter] || 'A'
page = params[:page] || 1
@products = Product.paginate_by_sql
['select * from products where symbol like ?', letter + '*'],
:page => page
:order => 'symbol'
But with this code in place, the page won't load. I see this in the log file, but it doesn't actually look like an error to me:
Processing ProductsController#index (for 127.0.0.1 at 2010-09-15 10:03:22) [GET] [4;36;1mProduct Load (9.0ms)[0m [0;1mselect * from products where symbol like 'A*' LIMIT 50 OFFSET 0[0m Rendering template within layouts/main Rendering products/index Completed in 21ms (View: 4, DB: 9) | 200 OK [http://localhost/products]
I realize I'm probably missing something obvious, or else not including the information that would be needed to solve this problem. Would anyone care to steer me in the right direction, or let me know what other info I should provide?