Carla Dessi
Carla Dessi

Reputation: 9666

rails "No route matches" even though it's in routes

I have this form:

<% @softwares.each do |l| %>
<tr>
    <td><%= l.vendor %></td>
    <td><%= l.title %></td>
    <td><%= l.edition %></td>
    <td><%= l.amount %></td>

    <td><%= link_to 'view', software_path %></td>

<% end %>

When i click on the view link i get this error:
No route matches {:action=>"show", :controller=>"softwares"}

However when i run rake routes it does show up:

software GET /softwares/:id(.:format) softwares#show

and if i type it into the browser manually it works fine

Upvotes: 0

Views: 118

Answers (2)

Stefan
Stefan

Reputation: 114178

For RESTful resources you can just pass the resource:

link_to 'view', l
# => <a href="/softwares/1">view</a>

Upvotes: 0

Amar
Amar

Reputation: 6942

Pass software object in path because it's a member route <%= link_to 'view', software_path(l) %>

Upvotes: 1

Related Questions