# Remote pagination using pagination\_links, link\_to\_remote and

**URL:** <https://www.ruby-forum.com/t/remote-pagination-using-pagination-links-link-to-remote-and/93050>\
**Category:** Rails\
**Created:** [April 26, 2007, 11:51pm UTC](https://www.ruby-forum.com/t/remote-pagination-using-pagination-links-link-to-remote-and/93050 "2007-04-26T23:51:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [April 26, 2007, 11:51pm UTC](https://www.ruby-forum.com/t/remote-pagination-using-pagination-links-link-to-remote-and/93050/1 "2007-04-26T23:51:43Z")

</div>

I have two controllers, ‘ads’ and ‘markets’. In the ads controller I  
have a  
page that shows some partials from the markets view. I could create  
partials within the ‘ads’ view and methods in the ‘ads’ controller but  
that  
seems like i would be out of bounds. Since the markets partials were  
identical to some pieces i had already created and I might want to use  
this  
partial elsewhere in the future, I thought it would be best to keep  
markets  
with markets.

So now I show a view within ads and I have a partial rendered using  
pagination. I want to be able to move from page to page within the list  
(and filter it) and ultimately choose a record/row from the list and use  
it  
within the current view. However, somewhere along the string of method  
calls to build the pagination links some method filters out my  
:controller  
and :action assignments and replaces them with the current values. So  
what  
should be /markets/min\_filter\_lookup/?page=2 ends up being  
/ads/assign\_markets/?page=2 (the current view). The result of course is  
an  
entire new page/layout being rendered and returned, where I only want  
the  
partial.

Below is the method I use to generate the remote pagination links. It  
started as a method in my application helper that I only used within one  
view/controller, but I recently added some additional params/cases to  
use it  
to handle my current situation. If you look at the code below you can  
see I  
have one line commented out. I replaced that url\_for call with the  
actual  
url, somewhat hard-coded, and it works. Maybe I don’t understand  
url\_for.  
Maybe it’s a combination of a few methods? (Either way I have a feeling  
that the answer is extremely simple)

def pagination\_links\_remote(paginator, controller = nil, prefix = ‘’)  
page\_options = {:window\_size =\> 4}  
target = prefix.nil? ? ‘filter\_by\_list’ : “#{prefix}\_filter\_by\_list”  
action = prefix.nil? ? ‘filter\_lookup’ : “#{prefix}\_filter\_lookup”

```
plinks = pagination_links_each(paginator, page_options) do |n|

  if controller.nil?
    options = {
      :url => {:action => action, :params => @params.merge({:page =>

```

n})},  
:update =\> target,  
:before =\> “Element.show(‘filter\_by\_activity\_indicator’)”,  
:success =\> “Element.hide(‘filter\_by\_activity\_indicator’)”  
}  
html\_options = {:href =\> url\_for(:action =\> action, :params =\> @  
params.merge({:page =\> n}))}  
else  
options = {

# :url =\> url\_for(:controller =\> controller, :action =\> action,

:params =\> @params.merge({:page =\> n})),  
:url =\> “/markets/min\_filter\_lookup/?page=#{n}”,  
:update =\> target,  
:before =\> “Element.show(‘filter\_by\_activity\_indicator’)”,  
:success =\> “Element.hide(‘filter\_by\_activity\_indicator’)”  
}  
html\_options = {:href =\> url\_for(:controller =\> controller,  
:action  
=\> action, :params =\> @params.merge({:page =\> n}))}  
end

```
  logger.debug "pagination_links html_options: 

```

#{html\_options.inspect}"  
logger.debug “pagination\_links controller: #{controller.inspect}”  
logger.debug “pagination\_links prefix: #{prefix.inspect}”

```
  link_to_remote(n.to_s, options, html_options)
end

if plinks
  "Page: #{plinks}"
else
  ''
end

```

end

Thanks,

John
