Ruby on rails Url生成错误:没有路由匹配
我有一个链接调用属于我笔记本的笔记,如下所示:Ruby on rails Url生成错误:没有路由匹配,ruby-on-rails,Ruby On Rails,我有一个链接调用属于我笔记本的笔记,如下所示: == link_to "#{note.title.upcase}", notebook_note_path(note), id: "note_name" 我不知道为什么我会出错 以下是我的路线: resources :notebooks do resources :notes end 因为您有嵌套的管线,所以需要将两个对象传递给helper方法。试着传递一个笔记本和一个笔记,而不仅仅是一个笔记: notebook_note_path(n
== link_to "#{note.title.upcase}", notebook_note_path(note), id: "note_name"
我不知道为什么我会出错
以下是我的路线:
resources :notebooks do
resources :notes
end
因为您有嵌套的管线,所以需要将两个对象传递给helper方法。试着传递一个
笔记本
和一个笔记
,而不仅仅是一个笔记
:
notebook_note_path(note.notebook, note)
作为参考,当您设置了routes.rb
时,请查看rake routes
的输出:
notebook_notes GET /notebooks/:notebook_id/notes(.:format) notes#index
POST /notebooks/:notebook_id/notes(.:format) notes#create
new_notebook_note GET /notebooks/:notebook_id/notes/new(.:format) notes#new
edit_notebook_note GET /notebooks/:notebook_id/notes/:id/edit(.:format) notes#edit
notebook_note GET /notebooks/:notebook_id/notes/:id(.:format) notes#show
PATCH /notebooks/:notebook_id/notes/:id(.:format) notes#update
PUT /notebooks/:notebook_id/notes/:id(.:format) notes#update
DELETE /notebooks/:notebook_id/notes/:id(.:format) notes#destroy
...
由于此路径的URI是
/notebooks/:notebook\u id/notes/:id
,因此必须同时有一个note id和一个note id(Rails将前面的冒号替换为传递到helper方法的资源的id)。您是否在routes.rb中创建了notebook\u note\u path
?我刚刚用我的routes编辑了q。我认为路线是正确的,除非我误解了什么。