首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails中未定义的方法`category_documentations_path‘。我的路径包含注释而不是文档

Rails中未定义的方法`category_documentations_path‘。我的路径包含注释而不是文档
EN

Stack Overflow用户
提问于 2018-03-29 04:12:17
回答 2查看 30关注 0票数 0

我尝试对一个嵌套的表单执行此操作,当我加载该表单(/categories/show.html.haml)时,我收到以下错误:

代码语言:javascript
复制
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

config/routes.rb

代码语言:javascript
复制
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“命令的输出:

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

发布于 2018-03-29 10:05:49

找到了。这是一个奇怪的错误..不知道它是从我的文本编辑器还是其他什么地方来的,但我复制了routes.rb的内容,删除了它,创建了一个新的routes.rb文件并粘贴了内容,现在它可以工作了。

票数 1
EN

Stack Overflow用户

发布于 2018-03-29 04:22:22

这些资源路由与'rails routes‘的输出不匹配--自从运行'rails routes’之后,您是否更改了routes.rb文件?如果你的routes.rb看起来像你上面说的那样,'rails routes‘应该返回如下内容(使用'documentations’而不是'comments'):

代码语言:javascript
复制
    category_documentations GET /categories/:category_id/documentations(.:format) comments#index
    category_documentations POST /categories/:category_id/documentations(.:format) comments#create
    ...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49543360

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档