2016-06-08 49 views
0

我刚刚做了一个名为Comments的新模型,现在我正在尝试创建一个视图,以便用户可以从UI留下评论(这里非常基本的东西)。但是,我遇到了这个错误uninitialized constant CommentsController::Comments为我的生活我无法弄清楚为什么它抛出这个错误,而不是只是渲染页面时,它被点击? 为了清晰起见,我将发布所有适用的代码和错误。未初始化的常量CommentsController ::评论 - Rails错误

MODEL:

class Comment < ActiveRecord::Base 
belongs_to :subscriber 
end 

CONTROLLER:

class CommentsController < ApplicationController 
def new 
    @comments = Comments.new 
end 
end 

ROUTES

Rails.application.routes.draw do 
devise_for :users 
resources :subscribers, except: :show 
resources :comments 

SCHEMA:

create_table "comments", force: :cascade do |t| 
    t.string "description" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    t.string "fav_drink" 
    t.string "visit_time" 
end 

查看:

<h2>Let us get to know you more <%= link_to 'Comment', new_comment_path %> </h2> 

这是我设置的链接,点击用户将留下评论的页面。

错误:

enter image description here

让我知道如果你需要查看了代码。谢谢!

+1

是不是你的模型名为'Comment'?没有's'? – SparK

+0

我相信它有's'我将在编辑中张贴架构 – Bitwise

+0

不是表格,模型类本身。 ActiveRecord为模型'class Comment'使用单数名称。 – SparK

回答

2

我刚刚作出了一个愚蠢的错误,并呼吁Comments.new代替Comment.new

1

模型中引用奇,因为它们的类。你犯了一个错误Comments.new,但应该是Comment.new

相关问题