# Rails link_to and HTML options

> How to pass HTML attributes like title to the Rails link_to helper method

- Author: Curtis Miller
- Published: 2006-10-27
- Categories: rails, how-to
- Canonical URL: https://millarian.com/posts/rails-link_to-and-html-options/

Just a small thing, but I needed to know how to do this and it took me a while to find. Hopefully this will help someone else out.

In HTML, we might declare a link like so

```html
<a title="Example" href="/controller/action">Click Here!</a>
```

Now, in Ruby on Rails, we want to declare a link, so we use the built in [link\_to](http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M000378) method like this

```erb
<%= link_to "Click Here!", :controller => "controller", :action => "action" %>
```

Hmmm… how do we squeeze a title in there? Luckily, the third parameter to `link_to` is a hash of HTML options.

```erb
<%= link_to "Click Here!", {:controller => "controller", :action => "action"}, {:title => "Example"} %>
```

That should do it. I feel like I still have so much to learn about Ruby on Rails, but the more I learn the more I **want** to learn!
