0

似乎有一些这样的问题,但我已经阅读了所有这些问题,但它们没有帮助。

我有这个views/towns/index.html.haml

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

我已经做了一个inspect并且town.idid正确的。

我的路线看起来不错,因为我可以去

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.

4

1 回答 1

2

towns_attractions应该是town_attractions_path。而已。

于 2013-06-27T09:32:32.993 回答