2013-06-27 17 views
0

似乎有幾個像這樣的問題,但我已經閱讀了所有這些問題,但他們沒有幫助。無法使link_to在嵌套資源上工作

我有這樣的views/towns/index.html.haml

= link_to "towns attractions", towns_attractions(town.id) 

我已經town.id做了inspectid是正確的。

我的路線似乎沒關係,因爲我可以去

http://127.0.0.1:3000/towns 

,我可以去

http://127.0.0.1:3000/towns/1/attractions 

,當我把我的link_to出來(因爲它打破)。

不過,我得到這個錯誤在index.html.haml

undefined method `towns_attractions' 

我已經嘗試了多元化的所有組合,沒有運氣!

我的路線:

resources :towns do 
    resources :attractions 
end 

耙路線:

town_attractions GET /towns/:town_id/attractions(.:format)  attractions#index 
         POST /towns/:town_id/attractions(.:format)  attractions#create 
    new_town_attraction GET /towns/:town_id/attractions/new(.:format) attractions#new 
       towns GET /towns(.:format)        towns#index 
         POST /towns(.:format)        towns#create 
      new_town GET /towns/new(.:format)       towns#new 
      edit_town GET /towns/:id/edit(.:format)     towns#edit 
       town GET /towns/:id(.:format)       towns#show 
         PUT /towns/:id(.:format)       towns#update 
         DELETE /towns/:id(.:format)       towns#destroy 

所有我想要的是去http://127.0.0.1:3000/towns/1/attractions哪來1town.id替代的鏈接。

回答

2

towns_attractions應該是town_attractions_path。而已。

+0

謝謝!啊,這麼簡單。 – ale