Link_to_unless_current

how can I use this link tag and add a class like “current” if it is the
current link?

anrake wrote:

how can I use this link tag and add a class like “current” if it is the
current link?

Hello!

<%= link_to "Back to", { :action=> ""} %>

<%= link_to "Back to", { :action => "" }, :popup => true %>

<%= link_to "Back to", { :action => "" }, :popup => ['new_window', 'height=300,width=600'] %>

<%= link_to "Back to", { :action => "" }, :confirm => "Are you sure?", :post => true %>

I’m sorry I don’t see how this is doing what I need. Perhaps I should
have explained more. Is there a way to using link_to_unless_current to
add the class=“current” attribute in a SPAN around the text instead of
an A

I suppose so. Thanks for the effort. I was hoping someone had some
code for a simple block I could just drop in.

2006/9/3, anrake [email protected]:

I suppose so. Thanks for the effort. I was hoping someone had some
code for a simple block I could just drop in.

In case of current link link_to_unless_current returns link text or
whatever block passed to method yields, so:

<%= link_to_unless_current(‘some text’, :action=>:someaction) {|link|
“<span class="current">#{link}”} %>

This should work.

Regards,
Rimantas

http://rimantas.com/

Never recognized this function before, but as far as I understand the
code, it is not really possible. You can use a block and parse the
returned value, but this seems a bit more difficult than creating the
link itself. But you can try.

Otherwise I would go for a css based solution to your problem. warp the
link in a span and style the span the way you want. And then style the
links within spans the way inactive links should appear.

wow, that is perfect. Thank you very much !

But doesn’t that put a span around all items, links and text?

In case of current link link_to_unless_current returns link text or
whatever block passed to method yields, so:

<%= link_to_unless_current(‘some text’, :action=>:someaction) {|link|
“<span class="current">#{link}”} %>

This should work.

Or better yet:
<%= link_to_unless_current(‘some text’, :action=>:someaction) {|link|
content_tag ‘span’, link, :class => ‘current’} %>

Regards,
Rimantas

http://rimantas.com/

Maximilian S. wrote:

But doesn’t that put a span around all items, links and text?

Take a look at this forum post, if you want to do custom tag stuff:
http://railsforum.com/viewtopic.php?id=318