【问题标题】:Use data-disabled-with on a non form submit button在非表单提交按钮上使用 data-disabled-with
【发布时间】:2015-06-11 22:54:07
【问题描述】:
Rails 为表单提交上的按钮标签提供了 data-disabled-with。超级棒。但是,链接标签没有得到这种期望的行为。它们可以很好地防止用户点击按钮太多次并产生不必要的效果。
有没有办法可以做类似的事情:
<a href="www.somewhere.com" data-disabled-with="Please Wait">Purchase me</a>
【问题讨论】:
标签:
ruby-on-rails
button
ujs
disable-link
【解决方案1】:
Rails 通过 link_to 帮助器的 :disable_with 参数提供此功能。 See docs.
例如:
link_to("Create", create_post_path(@post), remote: true, disable_with: "Creating...")
当然,通过 GET 请求创建资源并不是 Rails/REST 的惯用语……但希望这能说明如何使用它。