简单 Rails link_to

Easy Rails link_to

我正在遍历一组结果,我的代码中有这个 link_to

<%= link_to "", "#{expo.id}/edit" %>

我预计它会进入 <domain>/exhibitions/3/edit。 我已经在 /exhibitions 页面中,所以我就是从那里得到的。问题是,它会到达 <domain>/exhibitions/3 并在那里结束。出于某种原因,它没有标记 URL 的 edit 部分。谁能帮忙?谢谢!

更新

代码是这样包装的:

<% @exhibition.each do |expo| %>
    <%= link_to "", expo_edit_path(:id) %>
<% end %>

更新 2

我 运行 rake routes 但我的编辑路径确实不正确。现在的问题是URL。 URL 字面意思变成: http://localhost:3000/exhibitions/id/edit 它字面意思写出单词 id.

这是我的新 link_to 声明:<%= link_to "", edit_exhibition_path(:id) %>

错误如下:

ActiveRecord::RecordNotFound in ExhibitionsController#edit Couldn't find Exhibition with 'id'=id

使用类似

的东西
link_to "text", edit_expo_path(expo)

您应该使用 config/routes.rb 中定义的路由 - 阅读 rails 路由以查看格式。

您可能会发现 有帮助。
还有