HippoBlog
Web開発に関する備忘録や
日々の雑記ブログ
  • #Ruby on Rails
  • 2020年2月20日
ENTRY TITLE

[rails] link_toによく追加する:confirmを自前で

TEXT BY @hippohack@hippohack
TEXT BY @hippohack@hippohack
  • このエントリーをはてなブックマークに追加

link_to自体では何もアクションしない処理で、vueのメソッドを読んでいるのでrailsのヘルパー機能では意図した挙動にならない。

なので自前で処理する。

<%= link_to 'Delete histories', 'javascript:void(0)', { class: "btn btn-danger btn-sm", '@click': 'submit_delete_histories_form' } %>

hoge.vue

submit_delete_histories_form() {
  var res = confirm('Are you sure?')
  if (res) {
    document.querySelector('#delete-histories-form').submit();
  }
}

🔍参考サイト


最後までお読みいただき、ありがとうございました。

ご意見などありましたら@hippohackへDMをお願いいたします。

  • このエントリーをはてなブックマークに追加