【Rails7.0】削除リンクが作成出来ない

実現したいこと

削除リンクを作成しDeleteを機能させ、確認メッセージも表示されるようにしたい。

前提

調べたところ
Ruby on Rails 7.0では、rails-ujsが標準構成から外れ、Turboが標準構成に入った。
それに伴い、Deleteが機能せず確認メッセージも表示されなくなってしまったようですが、自分では対処しきれなかったので助けて欲しいです。

発生している問題・エラーメッセージ

Deleteが機能せず、確認メッセージも表示されない。

該当のソースコード

show.html.erb/users

1<section class="section"> 2 <div class="container"> 3 <div class="columns is-multiline"> 4 <% @user.posts.each do |post| %> 5 <div class="column is-4"> 6 <div class="card"> 7 <div class="card-image"> 8 <figure class="image is-4by3"> 9 <%= link_to post_path(post) do %> 10 <%= attachment_image_tag post, :image, fallback: "no-image.png" %> 11 <% end %> 12 </figure> 13 </div> 14 <div class="card-content"> 15 <div class="media"> 16 <div class="media-content"> 17 <%= link_to post_path(post), class: "panel-block" do %> 18 <span class="panel-icon"> 19 <i class="fas fa-book" aria-hidden="true"></i> 20 </span> 21 投稿を見る 22 <% end %> 23 <% if @user.id == current_user.id %> 24 <%= link_to edit_post_path(post), class: "panel-block" do %> 25 <span class="panel-icon"> 26 <i class="fas fa-edit"></i> 27 </span> 28 投稿を編集する 29 <% end %> 30 <%= link_to post_path(post), date: {turbo_method: :delete, turbo_confirm: "削除しますか?"}, class: "panel-block" do %> 31 <span class="panel-icon"> 32 <i class="fas fa-trash"></i> 33 </span> 34 投稿を削除する 35 <% end %> 36 <% end %> 37 </div> 38 </div> 39 <div class="content"> 40 <time><%= post.updated_at.strftime("%Y-%m-%d %H:%M") %></time>更新 41 </div> 42 </div> 43 </div> 44 </div> 45 <% end %> 46 </div> 47 </div> 48</section>

Gemfile

1source "https://rubygems.org" 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby "3.2.2" 5 6# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" 7gem "rails", "~> 7.0.7", ">= 7.0.7.2" 8 9# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] 10gem "sprockets-rails" 11 12# Use sqlite3 as the database for Active Record 13gem "sqlite3", "~> 1.4" 14 15# Use the Puma web server [https://github.com/puma/puma] 16gem "puma", "~> 5.0" 17 18# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] 19gem "importmap-rails" 20 21# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] 22gem "turbo-rails" 23 24# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] 25gem "stimulus-rails" 26 27# Build JSON APIs with ease [https://github.com/rails/jbuilder] 28gem "jbuilder" 29 30# Use Redis adapter to run Action Cable in production 31# gem "redis", "~> 4.0" 32 33# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] 34# gem "kredis" 35 36# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] 37# gem "bcrypt", "~> 3.1.7" 38 39# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 40gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] 41 42# Reduces boot times through caching; required in config/boot.rb 43gem "bootsnap", require: false 44 45# Use Sass to process CSS 46# gem "sassc-rails" 47 48# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] 49# gem "image_processing", "~> 1.2" 50 51group :development, :test do 52 # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem 53 gem "debug", platforms: %i[ mri mingw x64_mingw ] 54end 55 56group :development do 57 # Use console on exceptions pages [https://github.com/rails/web-console] 58 gem "web-console" 59 60 # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] 61 # gem "rack-mini-profiler" 62 63 # Speed up commands on slow machines / big apps [https://github.com/rails/spring] 64 # gem "spring" 65end 66 67group :test do 68 # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] 69 gem "capybara" 70 gem "selenium-webdriver" 71 gem "webdrivers" 72end 73 74gem 'devise' 75gem "refile", require: "refile/rails", github: 'manfe/refile' 76gem "refile-mini_magick" 77gem "bulma-rails"

試したこと

リンク内容https://zenn.dev/komaken/articles/900566822a84b6
こちらの記事を参考にgemはすでにインストールされていたので

$ rails importmap:install $ rails turbo:install stimulus:install

こちらのコマンドを実行したのですがDeleteメソッドが使用できません。

また
リンク内容https://picolab.dev/2022/03/23/rails7-turbo/
こちらの記事も参考に

<%= link_to post_path(post), date: {turbo_method: :delete, turbo_confirm: "削除しますか?"}, class: "panel-block" do %>

とコードを直したのですが、もしかしたらこちらのコードがおかしいのかもしれません。

よろしくお願いします。

補足情報(FW/ツールのバージョンなど)

Rails 7.0.7.2

コメントを投稿

0 コメント