2015-07-20 89 views
1

我通过结果的收集迭代,而我在我的代码有这样link_to易Rails的LINK_TO

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

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

UPDATE

的代码被包裹在此:

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

更新2

我已经运行rake routes,我确实有不正确的编辑路径。现在的问题是网址。网址字面上变成: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

+0

嗯,我认为你的两个部分现在编辑后不同步。 –

回答

3

使用类似

link_to "text", edit_expo_path(expo) 

你应该使用路由在配置定义/ routes.rb - 在rails路径上读取以查看格式。

您可能会感兴趣https://stackoverflow.com/a/12141379/631619对您有所帮助。
https://stackoverflow.com/a/29419670/631619

+0

我仍然收到此错误:未定义的方法“expo_edit_path”为#<#:0x007ff74d83c5b0>' – inthenameofmusik

+0

已更正。也请做'rake routes',看看有什么路径存在。您可能需要添加它。在你的问题中发布结果。 –

+0

我发布了新错误 – inthenameofmusik