Is there: disable_with equivalent for link_to_remote?

I have link_to_remote, and I want people to only be able to click on it once, waiting for it to return.

Is there any way to disable it after someone clicks it? (Changing the link text is also good, but I also want to disable it).

This is Ruby on Rails btw.

+3
source share
2 answers

I ended up replacing the link in the block: in front of the block, as 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>

Please note that this uses jQuery. If you use a prototype, you may need to change the ".html" method to the equivalent of the prototype (I suppose, ".update").

Then after an AJAX call, it redraws 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 , DRY

+3

, , , href.

, : : "" javascript.

+3

Source: https://habr.com/ru/post/1734935/


All Articles