0
似乎有幾個像這樣的問題,但我已經閱讀了所有這些問題,但他們沒有幫助。無法使link_to在嵌套資源上工作
我有這樣的views/towns/index.html.haml
:
= link_to "towns attractions", towns_attractions(town.id)
我已經town.id
做了inspect
和id
是正確的。
我的路線似乎沒關係,因爲我可以去
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
哪來1
被town.id
替代的鏈接。
謝謝!啊,這麼簡單。 – ale