# Paginate in another controller

**URL:** <https://www.ruby-forum.com/t/paginate-in-another-controller/148906>\
**Category:** Rails\
**Created:** [September 18, 2008, 8:17am UTC](https://www.ruby-forum.com/t/paginate-in-another-controller/148906 "2008-09-18T08:17:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 18, 2008, 8:17am UTC](https://www.ruby-forum.com/t/paginate-in-another-controller/148906/1 "2008-09-18T08:17:13Z")

</div>

When I’m in a controller and view A, and there bring up a layer with an  
id to list items from another controller B using AJAX (link\_to\_remote),  
how do I deal with that? I get an error with pure javascript on the page  
when clicking on the next button in the paginate nav bar. When hover  
over the next-link looking at the url it points at the controller B,  
obviously. But how do I stay in the current controller/view? I hope you  
understand my problem.

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 19, 2008, 10:54am UTC](https://www.ruby-forum.com/t/paginate-in-another-controller/148906/2 "2008-09-19T10:54:52Z")

</div>

PÃ¥l BergstrÃ¶m wrote:

> When I’m in a controller and view A, and there bring up a layer with an  
> id to list items from another controller B using AJAX (link\_to\_remote),  
> how do I deal with that? I get an error with pure javascript on the page  
> when clicking on the next button in the paginate nav bar. When hover  
> over the next-link looking at the url it points at the controller B,  
> obviously. But how do I stay in the current controller/view? I hope you  
> understand my problem.

Anyone? Is it possible to use a method containing the pagination-search  
from another controller but stay in the current view/controller?

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 19, 2008, 11:04am UTC](https://www.ruby-forum.com/t/paginate-in-another-controller/148906/3 "2008-09-19T11:04:11Z")

</div>

Sorry, I don’t understand your problem.  
You have a link to some ajax action. You click it and  
get the ajax response. What would you mean with  
“stay in the current controller”? After all html is a state less  
protocol and you’re never “in” a specific controller. Though  
the navbar may tell you where the actual page came from, but  
an ajax call doesn’t change that.  
And what exactly should “I get an error with pure javascript on the  
page  
when clicking on the next button…”. So this error is your problem?  
Then it would help tremendously if you would post that error.

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 19, 2008, 12:22pm UTC](https://www.ruby-forum.com/t/paginate-in-another-controller/148906/4 "2008-09-19T12:22:12Z")

</div>

> :page =\> params[:comments], :conditions =\> [“message\_id = ?”,  
> code.
> 
> This is my navigation/pagination
> 
> \<%= will\_paginate @comments, :param\_name =\> ‘comments’, :remote =\> {  
> :with =\> ‘value’, :update =\> “commentlist”}, :prev\_label =\> ‘\<’,  
> :next\_label =\> ‘\>’ %\>

ok, that’s an easy one.

you can use link\_to\_remote (and all related ajax link generating  
helpers)  
in two ways:  
with the :update option or without.

if you use it, as you do with :update =\> “commentlist”, then  
it expects pure html as response and will try to update the named  
element, “commentlist” in that case.  
So it interprets your response as HTML.  
remove the :update thing, you tell it with  
page.replace\_html “editarearight”  
that you want to replace another element anyway.

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 19, 2008, 12:31pm UTC](https://www.ruby-forum.com/t/paginate-in-another-controller/148906/5 "2008-09-19T12:31:37Z")

</div>

Thorsten M. wrote:  
t’s an easy one.

> you can use link\_to\_remote (and all related ajax link generating  
> helpers)  
> in two ways:  
> with the :update option or without.
> 
> if you use it, as you do with :update =\> “commentlist”, then  
> it expects pure html as response and will try to update the named  
> element, “commentlist” in that case.  
> So it interprets your response as HTML.  
> remove the :update thing, you tell it with  
> page.replace\_html “editarearight”  
> that you want to replace another element anyway.

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 19, 2008, 11:18am UTC](https://www.ruby-forum.com/t/paginate-in-another-controller/148906/6 "2008-09-19T11:18:59Z")

</div>

Thorsten M. wrote:

> Sorry, I don’t understand your problem.  
> You have a link to some ajax action. You click it and  
> get the ajax response. What would you mean with  
> “stay in the current controller”? After all html is a state less  
> protocol and you’re never “in” a specific controller. Though  
> the navbar may tell you where the actual page came from, but  
> an ajax call doesn’t change that.  
> And what exactly should “I get an error with pure javascript on the  
> page  
> when clicking on the next button…”. So this error is your problem?  
> Then it would help tremendously if you would post that error.

I’m in a controller/view ‘intranet’. There I have a \<%= link\_to\_remote  
“List Comments”, :url =\> {:controller =\> ‘messages’, :action =\>  
‘comments’, :id =\> message }, :html =\> { :style =\> ‘’} , :loading =\>  
“Element.show(‘timeloop’)”, :complete =\> “Element.hide(‘timeloop’)” %\>

This opens a div in ‘intranet’

\<%= render :partial =\> ‘messages/commentlist’ %\>

with this in messages\_controller

def comments  
@comments = Comment.paginate :per\_page =\> session[:comments\_listnr],  
:page =\> params[:comments], :conditions =\> [“message\_id = ?”,  
params[:id]]  
session[:message\_id] = params[:id]  
render :update do |page|  
page.show ‘editarearight’  
page.replace\_html ‘editarearight’, :partial =\> ‘messages/comments’  
end  
end

The list comes up and the navigation from paginations comes up fine. But  
when clicking the navigation I get an page with just text, javascript  
code.

This is my navigation/pagination

\<%= will\_paginate @comments, :param\_name =\> ‘comments’, :remote =\> {  
:with =\> ‘value’, :update =\> “commentlist”}, :prev\_label =\> ‘\<’,  
:next\_label =\> ‘\>’ %\>
