我尝试对一个嵌套的表单执行此操作,当我加载该表单(/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_pathconfig/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 route“命令的输出:
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发布于 2018-03-29 10:05:49
找到了。这是一个奇怪的错误..不知道它是从我的文本编辑器还是其他什么地方来的,但我复制了routes.rb的内容,删除了它,创建了一个新的routes.rb文件并粘贴了内容,现在它可以工作了。
发布于 2018-03-29 04:22:22
这些资源路由与'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
...https://stackoverflow.com/questions/49543360
复制相似问题