Disable link_to tag in Rails3+

Viewed 24003

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?

5 Answers

I'm not sure what @lamrin wanted with this question, but I suppose that it is something like this:

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

With this code above, the image would have a link if the condition? is true

In my case this code below worked (a more complicated example):

link_to_unless disabled, (content_tag :div, "", :class => "vote " + vote_class, :title => title), resource_user_path({ :id => resuser.id, :resource_user => {:id => resuser.id, :resource_id => resource_id, :user_id => current_user_id, :vote => vote_value}}), :remote => true, :method => http_method  

This link may also help with this approach:

http://railskey.wordpress.com/2012/07/19/rails-link_to-link_to_if-and-link_to_unless/

Related