简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM