Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Url生成错误:没有路由匹配_Ruby On Rails - Fatal编程技术网

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。我认为路线是正确的,除非我误解了什么。