LoginSignup
1

More than 3 years have passed since last update.

gem 'data-confirm-modal'でbootstrap風アラート

Posted at

準備

Bootstrapが必要なので使えるようにしておく必要があります。

gem:data-confirm-modalをインストール

Gemfile
gem 'data-confirm-modal'
bash
bundle install

application.jsに追記

application.js
//= require data-confirm-modal

こんな具合に書いて

index.html.erb
<%= link_to 'Destroy', user, method: :delete, data:
  { confirm: '本当に削除して良いですか?',
    cancel: 'やめる',
    commit: '削除する'}, title: '削除確認' %>

railsアプリケーションを再起動する

bash
bundle exec rails s

終了

これだけでdata-confirm のアラートをBootstarp風にできました。
before(chrome)
alt
after
alt

困ったこと

chromeとEdgeでは問題ないけど、IEだとデフォルトのアラートが一緒に表示されてしまう…。
他のgemとの相互作用?

Gemfile
ruby '2.5.3'
gem 'bootstrap', '~> 4.1.1'
gem 'jquery-rails'
gem 'data-confirm-modal'
gem 'rails', '~> 5.2.0'

alt

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
1