我尝试使用嵌套表单,当我加载表单(/categories/show.html.haml)时,我收到此错误:
NoMethodError in Categories#show
Showing /home/cederic/rails/mordus/app/views/categories/show.html.haml where line #6 raised:
undefined method `category_documentations_path' for #<#<Class:0x00007fead8742870>:0x00007fead8881038>
Did you mean? category_comments_path
配置/ routes.rb中
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
resources :categories do
resources :documentations
end
get 'pages/accueil'
root 'pages#accueil'
end
“rails routes”命令的输出:
refix Verb URI Pattern Controller#Action
category_comments GET /categories/:category_id/comments(.:format) comments#index
POST /categories/:category_id/comments(.:format) comments#create
new_category_comment GET /categories/:category_id/comments/new(.:format) comments#new
edit_category_comment GET /categories/:category_id/comments/:id/edit(.:format) comments#edit
category_comment GET /categories/:category_id/comments/:id(.:format) comments#show
PATCH /categories/:category_id/comments/:id(.:format) comments#update
PUT /categories/:category_id/comments/:id(.:format) comments#update
DELETE /categories/:category_id/comments/:id(.:format) comments#destroy
categories GET /categories(.:format) categories#index
POST /categories(.:format) categories#create
new_category GET /categories/new(.:format) categories#new
edit_category GET /categories/:id/edit(.:format) categories#edit
category GET /categories/:id(.:format) categories#show
PATCH /categories/:id(.:format) categories#update
PUT /categories/:id(.:format) categories#update
DELETE /categories/:id(.:format) categories#destroy
pages_home GET /pages/home(.:format) pages#home
root GET / pages#home
答案 0 :(得分:1)
找到它。这是一个奇怪的错误..不知道它是否来自我的文本编辑器或其他什么,但我复制routes.rb的内容,删除它,创建一个新的routes.rb文件并粘贴内容,现在它的工作原理。
答案 1 :(得分:0)
这些资源路由与'rails routes'的输出不匹配 - 你运行'rails routes'后是否更改了routes.rb
文件?如果您的routes.rb
看起来如上所述,'rails routes'应该返回以下内容(使用'documentations'而不是'comments'):
category_documentations GET /categories/:category_id/documentations(.:format) comments#index
category_documentations POST /categories/:category_id/documentations(.:format) comments#create
...