我刚刚做了一个名为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>
这是我设置的链接,点击用户将留下评论的页面。
错误:
让我知道如果你需要查看了代码。谢谢!
是不是你的模型名为'Comment'?没有's'? – SparK
我相信它有's'我将在编辑中张贴架构 – Bitwise
不是表格,模型类本身。 ActiveRecord为模型'class Comment'使用单数名称。 – SparK