是否有一个:disable_with相当于link_to_remote? [英] Is there a :disable_with equivalent for link_to_remote?

查看:131
本文介绍了是否有一个:disable_with相当于link_to_remote?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有link_to_remote,我想确保人们只能点击一次,等待其返回。

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).

这是Ruby on Rails的BTW。

This is Ruby on Rails btw.

推荐答案

我结束了更换链接中:之前像Edgard块提示:

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>

请注意这里使用JQuery的。如果您使用的原型,你可能需要的。html的方法更改为原型当量('.update我相信)。

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

然后AJAX调用时后重绘link_to_remote喜欢的东西......

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

在第一部分中的link_to_remote确实应该在相同的部分,以保持干燥

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

这篇关于是否有一个:disable_with相当于link_to_remote?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆