Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

link_to_unless_current assign class to disabled (current) link

link_to_unless_current assign class to disabled (current) link

Problem

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.


  'btn' %>

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

Problem courtesy of: prodigerati

Solution

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

 "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.

Solution courtesy of: James

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

link_to_unless_current assign class to disabled (current) link

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×