コメント機能の非同期通信に成功しまして
コメント削除ボタンも非同期通信させようと下記を追加したところ削除ボタンを押したところエラーが出ます
<a class="comment-delete" rel="nofollow" data-method="delete" href="/comments/${comment.user_id}">削除</a>
検証でコメント削除の部分をコピーしてきましてhref="/comments/${comment.user_id}の${comment.user_id}の部分を変更させて見ましたがうまく動作しません
エラーの文はActiveRecord::RecordNotFound in CommentsController#destroy
です。
href="/comments/${comment.user_id}の${comment.user_id}部分を${comment.id}にして見ましたが効果ありません。
create.json.jbuilderの記載がcomment.user_idなのであっていると思いますが・・・・
どうしたらいいでしょう?
ファイル views/commets/_comment.html.haml .comments %h4 <コメント一覧> - if @comments - @comments.each do |comment| %p %strong = link_to comment.user.nickname, "/users/#{comment.user_id}" : = comment.text - if user_signed_in? && current_user.id == comment.user_id = link_to "削除","/comments/#{comment.id}", method: :delete, class: "comment-delete"
ファイル javascripts/comment.js $(function(){ function buildHTML(comment){ var html = `<p> <strong> <a href=/users/${comment.user_id}>${comment.user_name}</a> : </strong> ${comment.text} <a class="comment-delete" rel="nofollow" data-method="delete" href="/comments/${comment.user_id}">削除</a> </p>` return html; }
ファイル名 views/commets/create.json.jbuilder json.text @comment.text json.user_id @comment.user.id json.user_name @comment.user.nickname
あなたの回答
tips
プレビュー