smptmhr / el-training

株式会社万葉の新入社員教育用カリキュラム
https://everyleaf.com/
2 stars 0 forks source link

Step8-5 タスク削除前に確認ポップを出す #19

Closed smptmhr closed 2 years ago

smptmhr commented 2 years ago

問題

rails newをするときに--minimalオプションを使用したので、data-confirmを呼び出すためのgemがインストールされていない。

やること

smptmhr commented 2 years ago

importmap-railsのインストール

  1. $bundle add importmap-rails
  2. $rails importmap:install

    turbo-railsのインストール

  3. Gemfileに追加 gem 'turbo-rails'
  4. $bundle install
  5. $rails turbo:install

viewで確認メッセージを出すように実装

<%= button_to "タスクを削除", @task, method: :delete,form: {data: {turbo_confirm: "本当に削除しますか?"} } %>

結果

スクリーンショット 2022-05-23 14 03 50

参考 : How to call confirm prompt using button_to in Rails with Turbo https://github.com/hotwired/turbo-rails https://github.com/rails/importmap-rails