# Link\_to with span

**URL:** <https://www.ruby-forum.com/t/link-to-with-span/173926>\
**Category:** Rails\
**Created:** [August 18, 2009, 10:41am UTC](https://www.ruby-forum.com/t/link-to-with-span/173926 "2009-08-18T10:41:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [August 18, 2009, 10:41am UTC](https://www.ruby-forum.com/t/link-to-with-span/173926/1 "2009-08-18T10:41:11Z")

</div>

Hi there,

I want to create a link with a ‘span’ inside such as

Home

I’m trying to do it so that it highlights the current navigation, using  
something I found online I have this.

def section\_link(name,options)  
if options[:action] == @current\_action and options[:controller] ==  
@current\_controller  
link\_to(name, options, :class =\> ‘on’)  
else  
link\_to(name,options)  
end  
end

So I effectively want the link\_to to be able to contain the span, any  
ideas?

Much appreciated!

Pete

---

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [August 18, 2009, 4:40pm UTC](https://www.ruby-forum.com/t/link-to-with-span/173926/2 "2009-08-18T16:40:23Z")

</div>

The first argument to link\_to can be any text you want, so include a  
span if you want:

link\_to( content\_tag( :span, “Hello”), options )

That being said, if you want the span to include everything inside the  
 tag, why not just apply the styling to the tag, as in the  
example you found?

 

On Aug 18, 1:41 am, Pete M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
