【发布时间】:2017-06-15 02:37:25
【问题描述】:
我正在尝试为特定帖子创建评论,当我点击评论时,我得到未初始化的常量 Squeals.. 我确实有路线
SQUEAL 模型
class Squeal < ActiveRecord::Base
has_many :comments, as: :commentable
end
comment.rb
class Comment < ActiveRecord::Base
belongs_to:commentable, polymorphic:true
end
/squeal/cmets_controller.rb
class Squeals::CommentsController <CommentsController
before_action :set_commentable
private
def set_commentable
@commentable = Squeal.find(params[:squeal_id])
end
end
cmets 控制器
class CommentsController < ApplicationController
before_action:authenticate_user!
def create
@comment = @commentable.comments.new comment_params
@user.user = current_user
comment.save
redirect_to @commentable, notice: "Your comment was posted"
end
private
def comment_params
params.require(:comment).permit(:body)
end
end
路线
resources :squeals do
resources :comments, module: :squeals
end
squeal/show.html.erb
【问题讨论】:
-
我们可以看看确切的错误日志输出吗?
标签: ruby-on-rails ruby