【发布时间】:2017-09-02 18:38:05
【问题描述】:
我在尝试向文章添加新评论时收到以下错误 (NoMethodError),问题是它引用了我在代码文件中找不到的未定义方法 `cmets_path'
请帮忙
注意: 我试图搜索这个错误,但我发现的结果不相关,问题是错误指向我找不到的东西。
错误如下图:
评论中的 NoMethodError#new 显示 /home/abc/my_ruby_projects/myblog3/app/views/cmets/_form.html.erb 其中第 1 行提出:
# 的未定义方法 `cmets_path' 你的意思?字体路径 提取的源代码(第 1 行附近):
<%= form_with model: @comment do |form| %>
<% if comment.errors.any? %>
<div id="error_explanation">
<....>
<ul>
模板包含的痕迹:app/views/cmets/new.html.erb
Rails.root:/home/abc/.../myblog3
我已经为文章和 cmets 定义了嵌套路由,如下所示:
resources :articles do
resources :comments
end
我的路线似乎是正确的,如下所示:
Prefix Verb URI Pattern Controller#Action
rails_admin /admin RailsAdmin::Engine
article_comments GET /articles/:article_id/comments(.:format) comments#index
POST /articles/:article_id/comments(.:format) comments#create
new_article_comment GET /articles/:article_id/comments/new(.:format) comments#new
edit_article_comment GET /articles/:article_id/comments/:id/edit(.:format) comments#edit
article_comment GET /articles/:article_id/comments/:id(.:format) comments#show
PATCH /articles/:article_id/comments/:id(.:format) comments#update
PUT /articles/:article_id/comments/:id(.:format) comments#update
DELETE /articles/:article_id/comments/:id(.:format) comments#destroy
articles GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article GET /articles/new(.:format) articles#new
edit_article GET /articles/:id/edit(.:format) articles#edit
article GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE /articles/:id(.:format) articles#destroy
【问题讨论】:
标签: ruby-on-rails ruby