Sort_link_helper and cross-controller partials

Hello Rubyists,

I ran into a problem with sorting a table (rendered in a partial) using
the sort_link_helper methods after I have submitted data and re-rendered
the table through an AJAX request.

The setup is a follows:

The table is a shared partial of Controller1 and Controller2 accessible
via “shared/table”. The AJAX’ed sorting using the sort helper works all
fine on Controller1.

An AJAX link in the table refers to a method named “mymethod” on
Controller2. Controller2 does what is expected from it and does a render
:partial => “shared/table” and the table is correctly displayed.

However, the links generated by sort_link_helper change to the format of
“/controller2/mymethod?aknownname=111802211&sort=my_sort_value”
instead of the expected (or desired)
“/controller1/list?sort=my_sort_value”.

The corresponding method in Controller2 looks like this:

def mymethod

… some code

if xhr?
render :partial => “shared/partial”, :layout => false
end
end

How can I tell the rendered partial to use links based on
“/controller1/list”? Thanks a lot in advance.

For a similar sort of problem I extended sort_link_helper, allowing it
to accept a hash of options. I then used the options to override the
controller/action/etc as needed. If you use a signature like:

sort_link_helper(text, params, options={}) you won’t have to change
the code anywhere else.

HTH,
AndyV