9
11

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.

Railsでform2重送信でハマる

Posted at

#2重送信防止
formなどで2重送信防止のため、送信中はボタンを押せなくして、"送信中..."なども文言を表示したいです。そういうときに、submit tagにdiabled_withオプションをつけると、簡単にその機能を実装できます。

#環境
Rails 4.2.4
ruby 2.2.0

#正解
<%= submit_tag "送信", "data-disable-with" => "送信中..."%>
または
<%= submit_tag "送信", data: {disable_with: '送信...'} %>

#間違い
<%= submit_tag "送信", disable_with: '送信...' %>

#ハマりポイント
data:をつけましょう。
あとはjqueryを内部的に使っているので、jquery-rails gemをいれて、

//= require jquery
//= require jquery-ujs

が必要です。

9
11
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
9
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?