ruby on rails - "Destroy" controller action appears to be looping through more than once -
i have model "comment", belongs_to model "user", in turn has_many comments. on 'users/edit' page, have link destroy comments:
users/edit.html.erb
<% @user.comments.each |comment| %> <%= link_to "destroy", destroy_comment_path(comment.id) %> <% end %> comments_controller
def destroy @comment = comment.find(params[:id]) @user = @comment.user @comment.destroy redirect_to edit_user_path(@user) end but i'm getting bizarre error. action appears looping through more once. i'm getting error message:
activerecord::recordnotfound in commentscontroller couldn't find comment id=[id of comment] with line being highlighted:
@comment = comment.find(params[:id]) the comment exists before call method, , no longer exists after call it. if remove line @comment.destroy action runs expected, , comment isn't destroyed. action must looping through again, after line. can't imagine why doing that. see might going wrong? don't have other actions called "destroy".
Comments
Post a Comment