2015-07-20 59 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