views:

34

answers:

1

My brain is fried trying to squeeze some work in before the holiday.

I'm trying to fix a simple bug. The URLs that the following link_to_remote is creating are wrong:

options = {
    :url => { :controller => 'favorites', :action => 'resort', :params => params.merge({:sort => key, :method => method})},
    :update => 'favorites'
}
html_options = {
  :title => "Sort by this field",
  :href => url_for(:controller => 'favorites', :action => 'resort', :params => params.merge({:sort => key, :method => method}))
}
link_to_remote("hithere", options, html_options)

It is creating:

http://localhost:3000/favorites?method=ASC&sort=title

instead of:

http://localhost:3000/favorites/resort?method=ASC&sort=title

The routes specified are:

  map.favorites_resort           "/favorites/resort",                                    :controller => "favorites", :action => "resort"
  map.favorites_search           "/favorites/search",                                    :controller => "favorites", :action => "search"
  map.toggle_message_favorite    "/favorites/toggle_message_favorite/:message_id",       :controller => "favorites", :action => "toggle_message_favorite"
  map.toggle_attachment_favorite "/favorites/toggle_attachment_favorite/:attachment_id", :controller => "favorites", :action => "toggle_attachment_favorite"
  map.resources :favorites

My guess is it has to do with some routing priorities but I can't figure out which... Thanks!

On jasnow's suggestion, changed routes to: map.favorites_resort "/favorites/resort/sort/:sort/method/:method"

+1  A: 

Look for the "/:" in your routes file.

jasnow
thanks, changed the route to map.favorites_resort "/favorites/resort/sort/:sort/method/:method"
Matt Rogish