prodigerati
prodigerati

Reputation: 607

link_to_unless_current assign class to disabled (current) link

Anyone know if you can assign a tag and class to the disabled or current link? The example below only displays as plain text in the browser for the current link.

I have a bit of rails code displaying a list of buttons for each design in the database.

<% @id_cards.each do |id| %>
 <%= link_to_unless_current id.design_type, id_card_design_path(id.id), :class => 'btn' %>
<% end %>

The active links are assigned the correct class and display as buttons.

Upvotes: 3

Views: 2993

Answers (2)

Sandip Ransing
Sandip Ransing

Reputation: 7733

@James gave proper answer its just you are too young to take it right :)

<% @id_cards.each do |id| %>
 <%=
 link_to_unless_current(id.design_type, id_card_design_path(id.id), :class => 'btn') do
  content_tag(:p, id.design_type, :class => :some_class
 end
 %>
<% end %>

Upvotes: 3

James
James

Reputation: 4807

link_to_unless_current accepts a block which can be used to override the default behavior.

http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to_unless_current

<%=
  link_to_unless_current("Comment", { :controller => "comments", :action => "new" }) do
    link_to("Go back", { :controller => "posts", :action => "index" })
  end
%>

In the example above it would yield the 'Go back' link if the current page was the 'new comment' page.

Upvotes: 5

Related Questions