0
当我尝试提交注释时出现错误。 - ActiveRecord的:: RecordNotFound在CommentsController#指数 - 我跟着this和this教程无法找到没有ID的注释 - 多态关联
的网址是:
.../articles/1/comments
comments_controller
class CommentsController < ApplicationController
before_action :set_comment
before_action :signed_in_user, only: [:new]
def index
@commentable = load_commentable
@comments = @commentable.comments
end
...
def create
@comment = @commentable.comments.new(comment_params)
@comment.user = current_user
if @comment.save
redirect_to @comment, notice: "Comment created."
else
render :new
end
end
....
private
def load_commentable
resource, id = request.path.split('/')[1, 2]
@commentable = resource.singularize.classify.constantize.find(id)
end
def set_comment
@comment = Comment.find(params[:id])
end
....
你可以在问题中分享完整的错误堆栈跟踪,这将有助于调试。 –
我加了全部跟踪 – Absurdim
看到我的回答,并记下'UPDATE'部分。 –