Link_to_remote url isn't recognized like link_to urls are?

I’m starting to learn about the Ajax support in Rails.

I had a link that looked like this:

link_to “View Game Details”, admin_game_path(@game)

and it worked great. (I’m using map.resources :games, :path_prefix =>
‘admin’, name_prefix => ‘admin_’)

Anyway, I wanted to try to learn some .rjs, so after writing my .rjs
script, I tried to invoke it by changing the link to this:

link_to_remote “View Game Details In The Div Below”, :url =>
admin_game_path(@game)

but clicking the link didn’t seem to do anything. Checking the
development.log file, I see that it’s because the route isn’t
recognized - it hit a route that was lower down in my routes.rb file,
which eventually caused a 500.

Without bothering everyone with my entire routes file (though I can if
needed), since I’m fairly new to Ajax, what’s the best way to go
about debugging this? I’ve done a View Source in the browser and the
generated url looks fine to me. So I have no idea why the routing
mechanism wouldn’t find the right match, like it does with a regular
link_to.

Is there something I can try in script/console to figure it out? Or
something like that?

Thanks!
Jeff

On Mar 23, 9:41 am, “Jeff” [email protected] wrote:

script, I tried to invoke it by changing the link to this:

link_to_remote “View Game Details In The Div Below”, :url =>
admin_game_path(@game)

but clicking the link didn’t seem to do anything. Checking the
development.log file, I see that it’s because the route isn’t
recognized - it hit a route that was lower down in my routes.rb file,
which eventually caused a 500.

Fixed. In case anyone else runs into this scenario, I’ll describe
what I did to solve it.

I commented out my catch-all route, and that yielded a more
informational error message, which was there was no route matching /
admin/games/5, :method => ‘POST’. Turns out the default method for
link_to_remote is POST, not GET. So I had to change my code to this:

link_to_remote “View Game Details In The Div Below”, :url =>
admin_game_path(@game), :method => :get

and then, lo and behold, my show action got called in the controller,
and I can render the rjs using a respond_to block.

I’m still not 100% clear on why the POST didn’t match a route -
shouldn’t it have matched the create action of my controller? That
still wouldn’t have been what I wanted, but it would have given me a
much better clue.

Jeff