Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable link_to tag in Rails3+

I used the following code:

<%= link_to image_tag("edit.png", :alt => "Edit"), edit_user_path(user) %>

I want to disable this link and image, so I added :disabled=>true to the code, but it's not disabling. Why not, and how do I disable them?

like image 361
lamrin Avatar asked Aug 03 '11 10:08

lamrin


1 Answers

Unlike buttons, hyperlinks cannot be "disabled". You can do the following though, assuming you have jQuery included on your pages:

<%=link_to image_tag("edit.png", :alt=>"Edit"), edit_user_path(user), :id => "mylink" %>

Add the following Javascript to your page:

$('#mylink').click(function(e){
  e.preventDefault();
});
like image 126
Gaurav Gupta Avatar answered Oct 05 '22 04:10

Gaurav Gupta