Luke
Luke

Reputation: 623

Rails link_to not working correctly

I am trying to put in a link_to on my table to go to the show action but it is putting the URL as /admin/vulnerabilities.object_id instead of /admin/vulnerabilities/object_id my index view is:

...
<% @vulnerabilities.each do |vulnerability| %>
  <tr>
    <td><%=link_to vulnerability.id, admin_vulnerabilities_path(vulnerability) %></td>
    <td><%= vulnerability.type %></td>
    <td><%=h truncate(vulnerability.description, :length => 80) %></td>
    <td><%= vulnerability.published %></td>
    <td><%= vulnerability.modified %></td>
    <td><%= link_to vulnerability.href, vulnerability.href , target: :_blank %></td>
  </tr>
<% end %>
...

I have a show.html.erb template setup and my show action is as follows:

def show
  @vulnerabilities = Vulnerability.find(params[:id])
end

From what I can see, this should work but when clicking the links it just redirects to the index page, effectively refreshing it and not using my show page at all.

Upvotes: 0

Views: 549

Answers (1)

jvillian
jvillian

Reputation: 20263

It would be helpful if you added the relevant parts of your routes.rb file to your question, but I speculate that the problem is that admin_vulnerabilities_path(vulnerability) should be admin_vulnerability_path(vulnerability).

Also, as noted in the comments, it is probably better to use @vulnerability as your instance name since find will return a single record.

Upvotes: 2

Related Questions