I’ve been working on an idea to use a server-side image map to allow
users to click anywhere in an area and have a new element appear at the
location they clicked. Everything was going well, until it came time to
connect the routing map. Here are the relevant parts:
In the view, the map is created by –
<%= link_to(image_tag(‘floor_plan.png’, :width => ‘1000’, :ismap =>
‘true’, :style => ‘position: absolute; top: 150px;’), :action =>
‘generate_ticket’) %>
A click anywhere on the map will generate a url of the form
“/report/generate_ticket?287,374” where 287 is the x-coord and 374 is
the y-coord. So in the routes.rb file we have (at the top of the list)
map.connect ‘:controller/:action?:x,:y’
Now, if I drop into the console, load up the routing map, and evaluate,
this is what I get –
rs = ActionController::Routing::Routes
=> #<ActionController::Routing::RouteSet:0x197da14
@routes_by_controller=nil, …>>rs.recognize_path ‘/report/generate_ticket?10,20’
=> {:action=>“generate_ticket”, :controller=>“report”, :y=>“20”,
:x=>“10”}
However, when I click on the image map, the params that are returned to
report#generate_ticket are –
{“287,374”=>nil, “action”=>“generate_ticket”, “controller”=>“report”}
Furthermore, if I remove all routes except for the one that should
handle the image map coordinates, then click on the map, I get –
no route found to match “/report/generate_ticket” with {:method=>:get}
and I get the same error if I type the URL in manually. What gives?