Remote pagination using pagination_links, link_to_remote and url_for

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