The link_to method is as which is not disabled:-
<%= link_to edit_cabinet_path(object), remote: true, disabled: true do %>
<span class="glyphicon glyphicon-pencil"></span>
<% end %>
but if i do like below which hides the link
<%= link_to edit_cabinet_path(object), remote: true, style: "display:none;" do %>
<span class="glyphicon glyphicon-pencil"></span>
<% end %>
Now the question is how to disable this type of link with block, and whats the reason that second code is working and first is not.
Probably, you are looking for link_to_if
. link_to_if
makes your link clickable only if your condition pass.
Your code should be something like:
<%= link_to_if false, edit_cabinet_path(object), remote: true do %>
<span class="glyphicon glyphicon-pencil"></span>
<% end %>
To make it dynamic you can call condition that satisfy whether to active or inactive that link, something like:
<%= link_to_if cabinate.active?,
"<span class='glyphicon glyphicon-pencil'></span>".html_safe,
edit_cabinet_path(object), remote: true %>
Hope this answer your question..
Actually there is no disabled
attribute available for link_to
, only for button_to
tag.
For more information please refer here: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
In this case, you might want to use link_to_if
, please have a look into this: http://apidock.com/rails/v4.2.1/ActionView/Helpers/UrlHelper/link_to_if
I wrote some simple JS to allow you to add disabled: true
to link_to
method
//this allows us to use html disabled attribute in rails
//to prevent clicking on a disabled link from doing anything
$('a[disabled]').click(function(e){
e.stopImmediatePropagation()
e.preventDefault();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With