我的Ruby文件中有一个评论页面,我在其中包含了一个"删除"按钮使用destroy方法。当我在我的本地主机上运行它时,它会抛出一个异常,如下所示;
NameError in Admin::CommentsController#destroy
uninitialized constant Comment::Notificaiton
Extracted source (around line #11):
def destroy
@comment = Comment.find(params[:id])
@comment.destroy
redirect_to :back, notice: 'Successfully deleted comment'
end
请注意:第11行是参考@ comment.destroy行!
这是我的完整comments_controller视图;
class Admin::CommentsController < Admin::ApplicationController
def index
@comments = Comment.where(status: to_bool(params[:status]))
end
def update
end
def destroy
@comment = Comment.find(params[:id])
@comment.destroy
redirect_to :back, notice: 'Successfully deleted comment'
end
end
这是我的路线视图;
Rails.application.routes.draw do
get '/login' => 'admin/sessions#new'
get '/logout' => 'admin/sessions#destroy'
namespace :admin do
resources :posts
resources :comments, only: [:index, :update, :destroy]
resources :tags, except: [:index]
resources :sessions, only: [:new, :create, :destroy]
resources :administrators, only: [:index, :edit, :update]
end
end
这是我对评论视图的索引;
<h1>Comments</h1>
<p>
<%= link_to 'Approved', admin_comments_path(status: true) %>
<%= link_to 'Un-Approved', admin_comments_path(status: false) %>
</p>
<% @comments.each do |comment| %>
<p><b><%= comment.user.fullname %></b> posted message on <b><%= comment.post.title %></b></p>
<p><%= comment.message %></p>
<p><%= link_to 'Delete', admin_comment_path(comment), method: :delete, data: {confirm: 'Are you sure?'} %></p>
<hr>
<% end %>
请你能解释我为什么遇到这个问题?
谢谢