[英]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: 我正在尝试在表上放入
link_to
以转到show
动作,但是它将URL设置为/admin/vulnerabilities.object_id
而不是/admin/vulnerabilities/object_id
我的索引视图是:
...
<% @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: 我有一个
show.html.erb
模板设置,我的show
动作如下:
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)
. 如果将route.rb文件的相关部分添加到问题中,将很有帮助,但是我推测问题是
admin_vulnerabilities_path(vulnerability)
应该是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. 另外,如注释中所述,最好使用
@vulnerability
作为实例名称,因为find
将返回单个记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.