views:

1469

answers:

3

I am trying to limit the number of elements returned with mislav's will paginate with Rails 3. I am currently using:

# Gemfile
gem 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git', :branch => 'rails3'

# company.rb
class Company < ActiveRecord::Base
  self.per_page = 8
end

# company_controller.rb
def index
  @companies = Company.where(...).paginate(:page => params[:page])
end

This does pagination, but not 8 items per page. If I modify the code to not use the "where" it works fine. However, adding "where" or "scoped" seems to cause issues. Any ideas what I'm doing wrong?

Thanks.

+3  A: 

Ended up being forced to move the per page limit into the query. Appears to be a bug with the Rails 3 version. Thus, fixed using:

@companies = Company.where(...).paginate(:page => params[:page], :per_page => 8)
Kevin Sylvestre
A: 

Why are you using 'Companies' and not 'Company'. This might just be a typo here but it appears to be an issue.

David Henner
Yeah, a typo. Fixed it now.
Kevin Sylvestre
+1  A: 

What about Ajax/UJS and will_paginate? Perhaps there is a way to do :remote => true?

Oto Brglez
You might want to consider asking it as normal question on the site.
Rekin