link_to_remote 是否有等效的 :disable_with ?

发布于 2024-08-23 05:01:30 字数 135 浏览 5 评论 0原文

我有一个 link_to_remote,我想确保人们在等待它返回时只能单击它一次。

有没有什么好的方法可以在有人点击后禁用它? (更改链接的文本也很好,但我也想禁用它以确保)。

顺便说一句,这是 Ruby on Rails。

I have a link_to_remote and I want to make sure people can only click it once while waiting for it to return.

Is there a good way to disable it after someone clicks it? (Changing the text of the link is nice too, but I want to disable it also to be sure).

This is Ruby on Rails btw.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一直在等你来 2024-08-30 05:01:30

您无法禁用链接,但可以更改 href 例如。

因此,您可以使用 :before 或 :loading 挂钩来使用 javascript “禁用”链接。

You can't disable a link, but you can change the href for example.

So you can use :before or :loading hooks to "disable" the link using javascript .

故事未完 2024-08-30 05:01:30

我最终像埃德加德建议的那样替换了 :before 块中的链接:

<div id="parent">
  <%= link_to_remote "Click Here",
    {:url => "/some_long_url",
    :method => :post,
    :before => "$('#parent').html('#{escape_javascript(link_to("Click Here"))}');"} %>
</div>

注意这使用了 JQuery。如果您使用原型,您可能需要将“.html”方法更改为原型等效方法(我相信“.update”)。

然后在进行 AJAX 调用后,它会使用类似的内容重绘 link_to_remote...

render :update do |page|
  page.replace_html  'parent', :partial => 'partial_containing_your_link_to_remote', :locals => {}
end

第一部分中的 link_to_remote 应该真正位于同一部分中以保持干燥

I ended up replacing the link in the :before block like Edgard suggested:

<div id="parent">
  <%= link_to_remote "Click Here",
    {:url => "/some_long_url",
    :method => :post,
    :before => "$('#parent').html('#{escape_javascript(link_to("Click Here"))}');"} %>
</div>

Note this uses JQuery. If you're using prototype you might need to change the '.html' method to the prototype equivalent ('.update' I believe).

Then after the AJAX call is made it redraws the link_to_remote with something like...

render :update do |page|
  page.replace_html  'parent', :partial => 'partial_containing_your_link_to_remote', :locals => {}
end

The link_to_remote in the first part should really be in that same partial to keep it DRY

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文