Hi all, I need to implement a navigation bar and use a dedicated css class for the current link. For example: <ul> <li><a href="" class="current">Current link</a></li> <li><a href="">Another link</a></li> </ul> I found link_to_unless_current but actually I''m not able to use it :o) This is what I have: <ul> <li> <%= link_to_unless_current ''Homepage'', { :controller => ''home'', :action => ''index'' }, { :class => ''current'' } %> </li> </ul> Of course it doesn''t work :/ Suggestions ? TIA, ngw -- checking for life_signs in -lKenny... no Oh my god, make (1) killed Kenny ! You, bastards ! nicholas_wieland-at-yahoo-dot-it
On 08/02/2005, at 8:45 PM, Nicholas Wieland wrote:> Hi all, I need to implement a navigation bar and use a dedicated css > class for the current link. > For example: > > <ul> > <li><a href="" class="current">Current link</a></li> > <li><a href="">Another link</a></li> > </ul>This is more CSS than Rails, but... It''s actually better from an accessibility POV to *not* link to the current page, so what link_to_unless_current does is not place <a> tags around the current link at all. But your stylesheet seems to be relying on the class="current", rather than the presence of the <a> tag itself. The common solution out there is to use <a> tags around the links, and a <span> for the current "link", which gives you a hook for styling things. So instead of your CSS looking for a specific class, it looks for either an anchor or span when styling the tabs/links. I ran into this same problem tonight, and my plan was to copy the code for link_to_unless_current and either redefine it with span tags, or just write my own helper called something like link_to_or_span()... I''ll have a go tomorrow and get back to you. What you need to modify on your CSS is another story altogether, but it IS possible :) --- Justin French, Indent.com.au justin.french-zULN+VWqVOIpAS55Wn97og@public.gmane.org Web Application Development & Graphic Design
On 8.2.2005, at 17:25, Justin French wrote:> On 08/02/2005, at 8:45 PM, Nicholas Wieland wrote: > >> Hi all, I need to implement a navigation bar and use a dedicated css >> class for the current link. >> For example: >> >> <ul> >> <li><a href="" class="current">Current link</a></li> >> <li><a href="">Another link</a></li> >> </ul> > > This is more CSS than Rails, but... > > It''s actually better from an accessibility POV to *not* link to the > current page, so what link_to_unless_current does is not place <a> > tags around the current link at all. > > But your stylesheet seems to be relying on the class="current", rather > than the presence of the <a> tag itself. The common solution out > there is to use <a> tags around the links, and a <span> for the > current "link", which gives you a hook for styling things. So instead > of your CSS looking for a specific class, it looks for either an > anchor or span when styling the tabs/links. > > I ran into this same problem tonight, and my plan was to copy the code > for link_to_unless_current and either redefine it with span tags, or > just write my own helper called something like link_to_or_span()... > I''ll have a go tomorrow and get back to you.You can sneak a code block into link_to_unless_current. In that block you can define the exact syntax to be used (class or different tags). See http://rails.rubyonrails.com/classes/ActionView/Helpers/ UrlHelper.html#M000216 //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails