Url_for , controller routing error

I have an ‘account_controller.rb’ in an ‘admin’ module
I list the accounts with : http://0.0.0.0:3000/admin/accounts/list,
and get my table

trying to sort it, I use the follwoing sort_link_helper :

def sort_link_helper(text, param)
  key = param
  key += "_reverse" if @params[:sort] == param
  options = {
      :url => {:action => 'list', :params => @params.merge({:sort => 

key, :page => nil})},
:update => ‘table’,
:before => “Element.show(‘spinner’)”,
:success => “Element.hide(‘spinner’)”
}
html_options = {
:title => “Sort by this field”,
:href => url_for(:action => ‘list’, :params =>
@params.merge({:sort => key, :page => nil}))
}
link_to_remote(text, options, html_options)
end

but the url_for generates the href:
http://0.0.0.0:3000/admin/admin/accounts/list?sort=login
even if I try to insert a :controller => ‘/admin/account’ , nothing
change
@params : “{"action"=>"list", "controller"=>"admin/accounts"}”
which seems correct, but the href is not… <a
href=“/admin/admin/accounts/list?sort=login”

I believe my problem is in the routing map, I have presently only
map.connect ‘:controller/:action/:id’, :controller => ‘user’, :action
=> ‘welcome’

maybe I should have a map identifying the admin module… but I don’t
know how to write it ?

thanks for any help

kad

even if I try to insert a :controller => ‘/admin/account’ , nothing
change
@params : “{“action”=>“list”, “controller”=>“admin/accounts”}”
which seems correct, but the href is not… <a
href="/admin/admin/accounts/list?sort=login"

From the @params line above, it looks like you did not specify the
leading slash (even though your comment on the line above has it). I
think you need it.

Kad K. wrote:

I have an ‘account_controller.rb’ in an ‘admin’ module
I list the accounts with : http://0.0.0.0:3000/admin/accounts/list,
and get my table

but the url_for generates the href:
http://0.0.0.0:3000/admin/admin/accounts/list?sort=login

I’m getting this same behavior. Anybody have an idea for a fix or at
least what’s causing it?

Thanks

ats

Kad K. wrote:

trying to sort it, I use the follwoing sort_link_helper :

def sort_link_helper(text, param)
  key = param
  key += "_reverse" if @params[:sort] == param
  options = {
      :url => {:action => 'list', :params => @params.merge({:sort => 

key, :page => nil})},
:update => ‘table’,
:before => “Element.show(‘spinner’)”,
:success => “Element.hide(‘spinner’)”
}
html_options = {
:title => “Sort by this field”,
:href => url_for(:action => ‘list’, :params =>
@params.merge({:sort => key, :page => nil}))
}
link_to_remote(text, options, html_options)
end

but the url_for generates the href:
http://0.0.0.0:3000/admin/admin/accounts/list?sort=login
even if I try to insert a :controller => ‘/admin/account’ , nothing
change
@params : “{"action"=>"list", "controller"=>"admin/accounts"}”
which seems correct, but the href is not… <a
href=“/admin/admin/accounts/list?sort=login”

I’ve created a work around about the problem. It’s a kludge, but is
seems to work.
The params.merge(…) is in there so you keep the values of the
parameters from previous requests. The problems is that :controller is
set and the value causes problems. It works fine if modules aren’t
involved, but the added members of the controller path cause problems
when using modules.

Two options to fix:

  1. Get rid of the params.merge call and expicitly add a :value =>
    params[:value] statement to the array for all properties you want to
    save.

or

  1. Clear out the :controller in the array passed to params.merge(…,
    :controller => nil)

This is probably a bug in url_for, but these workaround should work.

ats