# Paginate\_by\_sql giving errors

**URL:** <https://www.ruby-forum.com/t/paginate-by-sql-giving-errors/157877>\
**Category:** Rails\
**Created:** [January 16, 2009, 7:27am UTC](https://www.ruby-forum.com/t/paginate-by-sql-giving-errors/157877 "2009-01-16T07:27:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeba-momin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/8e7dd6/32.png) [@zeba-momin](https://www.ruby-forum.com/u/zeba-momin)\
**Post date:** [January 16, 2009, 7:27am UTC](https://www.ruby-forum.com/t/paginate-by-sql-giving-errors/157877/1 "2009-01-16T07:27:19Z")

</div>

Hi,  
I’m using paginate\_by\_sql to have pagination for my list views as my  
queries have joins on multiple tables.  
I have included the code into my application.rb , and in the controller  
I have:

@discipline\_pages, @disciplines = paginate\_by\_sql(Discipline,query,2)

But I get error as:

wrong number of arguments (4 for 2)

app/controllers/application.rb:63:in `initialize' app/controllers/application.rb:63:in`new’  
app/controllers/application.rb:63:in `paginate_by_sql' app/controllers/discipline_controller.rb:140:in`list’

At application.rb:63 I have:

object\_pages = Paginator.new self, total, per\_page,params[‘page’]

Please can someone help me with this…  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![zeba-momin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/8e7dd6/32.png) [@zeba-momin](https://www.ruby-forum.com/u/zeba-momin)\
**Post date:** [January 16, 2009, 8:05am UTC](https://www.ruby-forum.com/t/paginate-by-sql-giving-errors/157877/2 "2009-01-16T08:05:25Z")

</div>

Hey,  
I was able to solve the earlier error by changing application.rb:63 to:  
object\_pages = Paginator.new self, total, per\_page,@params[‘page’]

But now I have another error which says…

You have a nil object when you didn’t expect it!  
You might have expected an instance of ActiveRecord::Base.  
The error occurred while evaluating nil.[]

app/controllers/application.rb:63:in `paginate_by_sql' app/controllers/discipline_controller.rb:140:in`list’

Where am I going wrong…  
Can someone please help…  
Thanks.

Jeba M. wrote:

> Hi,  
> I’m using paginate\_by\_sql to have pagination for my list views as my  
> queries have joins on multiple tables.  
> I have included the code into my application.rb , and in the controller  
> I have:
> 
> @discipline\_pages, @disciplines = paginate\_by\_sql(Discipline,query,2)
> 
> But I get error as:
> 
> wrong number of arguments (4 for 2)
> 
> app/controllers/application.rb:63:in `initialize' app/controllers/application.rb:63:in`new’  
> app/controllers/application.rb:63:in `paginate_by_sql' app/controllers/discipline_controller.rb:140:in`list’
> 
> At application.rb:63 I have:
> 
> object\_pages = Paginator.new self, total, per\_page,params[‘page’]
> 
> Please can someone help me with this…  
> Thanks in advance.
