Is there a :disable_with equivalent for link_to_remote?

北城以北 提交于 2019-12-04 13:10:30

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 .

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!