# Need to add XTHML class attribute, link\_to's html options?

**URL:** <https://www.ruby-forum.com/t/need-to-add-xthml-class-attribute-link-tos-html-options/108970>\
**Category:** Rails\
**Created:** [July 10, 2007, 5:06am UTC](https://www.ruby-forum.com/t/need-to-add-xthml-class-attribute-link-tos-html-options/108970 "2007-07-10T05:06:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 10, 2007, 5:06am UTC](https://www.ruby-forum.com/t/need-to-add-xthml-class-attribute-link-tos-html-options/108970/1 "2007-07-10T05:06:26Z")

</div>

I need to add a class attribute to the elements generated by link\_to  
for my CSS to style the links.  
How can I do that?

\<%= link\_to “Artworks”, :controller =\> “artwork”, :action =\> “list” %\>

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 10, 2007, 5:16am UTC](https://www.ruby-forum.com/t/need-to-add-xthml-class-attribute-link-tos-html-options/108970/2 "2007-07-10T05:16:27Z")

</div>

dangerwillrobinsondanger wrote:

> I need to add a class attribute to the elements generated by link\_to  
> for my CSS to style the links.  
> How can I do that?
> 
> \<%= link\_to “Artworks”, :controller =\> “artwork”, :action =\> “list” %\>

\<%= link\_to ‘My Homepage’, get\_home\_page.last, :class =\> ‘navlink3’ %\>

–  
Phlip  
[Test Driven Ajax (on Rails) [Book]](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 10, 2007, 5:56am UTC](https://www.ruby-forum.com/t/need-to-add-xthml-class-attribute-link-tos-html-options/108970/3 "2007-07-10T05:56:29Z")

</div>

Thanks, but that approach using this:

\<%= link\_to “Artworks”, :controller =\> “artwork”, :action =\>  
“list”, :class =\> “artwork” %\>

…generates this:

[Artworks](https://www.ruby-forum.com/artwork/list?class=artwork)

That definitely renders, but renders something different from what I  
need.  
I need to generate this:  
[Artworks](https://www.ruby-forum.com/artwork/list)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 10, 2007, 6:03am UTC](https://www.ruby-forum.com/t/need-to-add-xthml-class-attribute-link-tos-html-options/108970/4 "2007-07-10T06:03:30Z")

</div>

Aha!! I got it!

\<%= link\_to “Artworks”, :controller =\> “artwork”, :action =\>  
“list”, :class =\> “artwork” %\>

needs to be:

\<%= link\_to “Artworks”, {:controller =\> “artwork”, :action =\>  
“list”}, :class =\> “artwork” %\>

Voila!
