I’m pretty new to Rails and I’m stuck getting a named route working properly. There are a lot of similar questions but I think I’ve got a different problem. It’s the first time I’ve used a named route with a parameter.
Firstly, this is Rails 3.0.9. I’ve got an entry in routes.rb:
get '/tasklist/:id' => 'projects#task_list'
Running rake routes shows the line:
GET /tasklist/:id(.:format) {:controller=>"projects", :action=>"task_list"}
My view has the following code:
<%= link_to image_tag("icons/add.png"), tasklist_path, :id => project.id %>
But when displaying the view it shows an error:
No route matches {:controller=>"projects", :action=>"task_list"}
...
Extracted source (around line #39):
39: <td><%= link_to image_tag("icons/add.png"), tasklist_path, :id => project.id %></td>
I just can’t see where the problem is here. Note that visiting the URL http://localhost:3000/tasklist/2 does appear to work just fine. Any ideas?
Try adding
:as => "tasklist"to your route.