# How to insert class name with link\_to

**URL:** <https://www.ruby-forum.com/t/how-to-insert-class-name-with-link-to/83225>\
**Category:** Rails\
**Created:** [January 24, 2007, 2:17pm UTC](https://www.ruby-forum.com/t/how-to-insert-class-name-with-link-to/83225 "2007-01-24T14:17:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![abon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@abon](https://www.ruby-forum.com/u/abon)\
**Post date:** [January 24, 2007, 2:17pm UTC](https://www.ruby-forum.com/t/how-to-insert-class-name-with-link-to/83225/1 "2007-01-24T14:17:58Z")

</div>

For example:

[www.example.com](http://www.example.com)

Thanks

---

<div class="post-metadata">

**Author:** ![abon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@abon](https://www.ruby-forum.com/u/abon)\
**Post date:** [January 24, 2007, 3:40pm UTC](https://www.ruby-forum.com/t/how-to-insert-class-name-with-link-to/83225/2 "2007-01-24T15:40:43Z")

</div>

Bontina C. wrote:

> For example:
> 
> [www.example.com](http://www.example.com)
> 
> Thanks

> **[Ruby on Rails](https://rubyonrails.org/)**
>
> A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.

Something like:  
autolink “Come to htttp://www.example.com”, href\_options = {:class =\>  
“example\_class”}

or

autolink “Come to htttp://www.example.com”, href\_options =  
{class=“example\_class”}

Haven’t really tried.

---

<div class="post-metadata">

**Author:** ![abon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@abon](https://www.ruby-forum.com/u/abon)\
**Post date:** [January 24, 2007, 4:07pm UTC](https://www.ruby-forum.com/t/how-to-insert-class-name-with-link-to/83225/3 "2007-01-24T16:07:07Z")

</div>

link\_to(name, options = {}, html\_options = nil,  
\*parameters\_for\_method\_reference)

so that would be

link\_to “mylink”, { :controller =\> “mycontroller”, :action =\>  
“myaction” }, { :class =\> “myclass” }

becomes

[mylink](http://mysite.com/mycontroller/myaction)

---

<div class="post-metadata">

**Author:** ![abon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@abon](https://www.ruby-forum.com/u/abon)\
**Post date:** [January 24, 2007, 5:41pm UTC](https://www.ruby-forum.com/t/how-to-insert-class-name-with-link-to/83225/4 "2007-01-24T17:41:32Z")

</div>

Chris H. wrote:

> link\_to(name, options = {}, html\_options = nil,  
> \*parameters\_for\_method\_reference)
> 
> so that would be
> 
> link\_to “mylink”, { :controller =\> “mycontroller”, :action =\>  
> “myaction” }, { :class =\> “myclass” }
> 
> becomes
> 
> [mylink](http://mysite.com/mycontroller/myaction)

But you still need to use auto\_link (auto\_link\_urls), when it’s an  
external link, right?

---

<div class="post-metadata">

**Author:** ![abon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@abon](https://www.ruby-forum.com/u/abon)\
**Post date:** [January 24, 2007, 6:09pm UTC](https://www.ruby-forum.com/t/how-to-insert-class-name-with-link-to/83225/5 "2007-01-24T18:09:51Z")

</div>

i don’t see how auto\_link has anything to do with his question. he  
asked about adding a class attribute using link\_to

and to answer your question, no. autolink just replaces urls and/or  
email addresses in a string with the appropriate anchor tag. doesn’t  
matter where the url goes.

---

<div class="post-metadata">

**Author:** ![abon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@abon](https://www.ruby-forum.com/u/abon)\
**Post date:** [January 24, 2007, 8:46pm UTC](https://www.ruby-forum.com/t/how-to-insert-class-name-with-link-to/83225/6 "2007-01-24T20:46:27Z")

</div>

Chris H. wrote:

> i don’t see how auto\_link has anything to do with his question. he  
> asked about adding a class attribute using link\_to
> 
> and to answer your question, no. autolink just replaces urls and/or  
> email addresses in a string with the appropriate anchor tag. doesn’t  
> matter where the url goes.

Can you use link\_to when you want to link to an external site at all?  
[http://www.imdb.com/bestmovieever/img/2.jpg](http://www.imdb.com/bestmovieever/img/2.jpg) ? That’s why I used  
auto\_link, filters through and makes a link of [http://whatever](http://whatever).

---

<div class="post-metadata">

**Author:** ![abon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@abon](https://www.ruby-forum.com/u/abon)\
**Post date:** [January 24, 2007, 10:00pm UTC](https://www.ruby-forum.com/t/how-to-insert-class-name-with-link-to/83225/7 "2007-01-24T22:00:43Z")

</div>

auto\_link “go here: [http://www.yahoo.com](http://www.yahoo.com) and send an email to  
removed\_email\_address@domain.invalid”

translates to

"go here: [http://www/yahoo.com](http://www.yahoo.com) and  
send an email to \<a href=“mailto:removed\_email\_address@domain.invalid\>removed\_email\_address@domain.invalid”

link\_to “go here” “[http://www.yahoo.com](http://www.yahoo.com)”

translates to

“[go here](http://www.yahoo.com)”

 

there’s a difference. one replaces urls and email addresses with  
anchor tags in a string, the other generates an anchor tag from a name  
and url (and any options).
