3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 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

3
1
0

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
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?