実現したいこと
ダイアログを表示し、削除を実行する実装を行いたい。
前提
rails7にて掲示板アプリの制作を行なっています。
発生している問題・エラーメッセージ
削除を押下するとエラーが発生してしまう。
No route matches [GET] "/comments/15" Rails.root: /app Application Trace | Framework Trace | Full Trace Routes Routes match in priority from top to bottom
該当のソースコード
<div class="p-comment__item"> <p><%= simple_format(comment.comment) %></p> <div class="p-comment__bottomLine"> <span><%= comment.name %></span> <span><%= comment.created_at.to_formatted_s(format = :datetime_jp) %></span> <span><%= link_to '削除', comment, data: {turbo_method: :delete, turbo_confirm: 'Are you sure?'} %></span> </div> </div>
class CommentsController < ApplicationController def create comment = Comment.new(comment_params) if comment.save flash[:notice] = 'コメントを投稿しました' redirect_to comment.board else flash[:comment] = comment flash[:error_messages] = comment.errors.full_messages redirect_back fallback_location: comment.board end end def destroy comment = Comment.find(params[:id]) comment.delete redirect_to comment.board, flash: { notice: 'コメントが削除されました' } end private def comment_params params.require(:comment).permit(:board_id, :name, :comment) end end
試したこと
rails7系よりturboの導入をされたことから<%= link_to '削除', comment, method: :delete, data: { confirm: '削除してよろしいですか?' } %>
のコードから現在のエラーのコードに変更してみたりしました。
button_toにてコードを作成すると削除はされるが、confirmが表示されない状態です。
ご教授よろしくお願いします。
0 コメント