# Will\_paginate paginates all instead of subclass

**URL:** <https://www.ruby-forum.com/t/will-paginate-paginates-all-instead-of-subclass/142966>\
**Category:** Rails\
**Created:** [July 14, 2008, 2:07am UTC](https://www.ruby-forum.com/t/will-paginate-paginates-all-instead-of-subclass/142966 "2008-07-14T02:07:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![THEBIGO](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@THEBIGO](https://www.ruby-forum.com/u/THEBIGO)\
**Post date:** [July 14, 2008, 2:07am UTC](https://www.ruby-forum.com/t/will-paginate-paginates-all-instead-of-subclass/142966/1 "2008-07-14T02:07:14Z")

</div>

I’m still a newb but having fun - Any help on this problem will be  
much appreciated.  
I have mymodel Call.rb

class Call \< ActiveRecord::Base  
belongs\_to :user  
has\_many:visits, :dependent =\> :destroy  
has\_many:visits do  
def latest  
find :all, :order =\> ‘id DESC’, :limit =\> 3  
end

```
    def all_latest
        find :all, :order => 'id DESC'
    end
end

```

def self.search(search, page)  
paginate :per\_page =\> 4, :page =\> page,  
:conditions =\> [‘name like ?’, “%#{search}%”],  
:order =\> ‘name’  
end  
end

And my controller for CallsController with index action

class CallsController \< ApplicationController  
before\_filter :login\_required, :only =\>  
[ :new, :create, :show, :index, :list, :all\_show, :edit, :update,  
:delete ]

def index

```
 @calls = Call.search(params[:search], params[:page])

```

end

my view page for index is

\<% form\_tag calls\_path, :method =\> ‘get’ do %\>

\<%= text\_field\_tag :search, params[:search] %\>  
\<%= submit\_tag “Search”, :name =\> nil %\>

  
\<% end %\>

\<% for call in @calls %\>  
\<%= link\_to h(call.name), :action =\> ‘show’, :id =\> call %\>  
\<% end %\>

  

\<%= will\_paginate @calls %\>

And what happens is that the paginate shows all the calls in the  
database for all the users but I only want  
it to paginate the current users calls. I’ve tried all sorts of  
things but not sure what to do. any suggestions will be  
appreciated. if you need more of my code let me know. I used the  
rails cast and obie Fernandez book and  
looked on line

---

<div class="post-metadata">

**Author:** ![THEBIGO](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@THEBIGO](https://www.ruby-forum.com/u/THEBIGO)\
**Post date:** [July 14, 2008, 5:00am UTC](https://www.ruby-forum.com/t/will-paginate-paginates-all-instead-of-subclass/142966/2 "2008-07-14T05:00:19Z")

</div>

I got my call index view to only display the calls for the curren\_user  
but it does not paginate them into pages.  
I want 4 per page as noted in my model but all of the calls show on  
the first page. Can anyone notice why

i changed the view line \<% for call in @calls %\>  
to  
\<% for call in @current\_user.calls %\> and then the link which works  
fine but then when I have the  
\<%= will\_paginate @calls %\> it messes up  
Any Ideas would be greatly appreciated  
Owen
