2017-04-26 126 views
1

我想從我的視圖使用link_to到嵌套的路由,我相信我只是我的語法不正確。我的應用程序的基本流程是有一個摘要,其中有許多提要,然後有許多日誌行。它的一個非常基本的報告Rails與link_to嵌套路由

我的路線是

resources :perfsums, :only => [:index] do 
    resources :perffeedresults, :only => [:index] do 
      resources :loglines, :only => [:index] do 
      end 
    end 
    end 

這裏是耙路線的外觀爲

perfsum_perffeedresult_loglines_path GET  /perfsums/:perfsum_id/perffeedresults/:perffeedresult_id/loglines(.:format)  loglines#index 

在我看來,我有一個鏈接,我想從進料鏈接類來使用Feed ID記錄行。應該很簡單。我對長相鏈接這樣

<td> <%= link_to c.id, perfsum_perffeedresult_loglines(c) %> </td> 

直接用手去的頁面可以作爲下面的鏈接顯示我只是不能到那裏形成鏈接

http://localhost:3000/perfsums/19/perffeedresults/143/loglines 

當我嘗試與運行link_to我得到。我在這裏嘗試了幾個不同的選項,都沒有工作。

undefined method `perfsum_perffeedresult_loglines' for #<#<Class:0x007fad31b60dd8>:0x007fad386d86b0> 

我使用的link_to從彙總到飼料的頁面去細嵌套牛逼帽子扔我送行,我認爲它只是額外位。

回答

1

首先,它是一個perfsum_perffeedresult_loglines_path,您錯過了_path,應該添加它以獲取路徑。而你需要傳遞兩個參數,看看路徑:

/perfsums/:perfsum_id/perffeedresults/:perffeedresult_id/loglines 

你需要通過一個perfsumperffeedresult

<td> <%= link_to c.id, perfsum_perffeedresult_loglines_path(perfsum, perffeedresult) %> </td> 
+1

感謝您對塗料巴掌這個工作​​<%=的link_toÇ .id,perfsum_perffeedresult_loglines_path(c.perfsummaryid,c.id)%> – ducati1212

+0

@ ducati1212沒問題! –