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'部分。 –