Posts tagged ActionView
Rails' link_to always gives me a headache
After 9 years of writing Ruby on Rails code, link_to()
never ceases to trip me up. Does it trip you up, too? Here are some quick notes:
- The first argument is what you want inside the
<a>
tag. For examplelink_to("today's news")
produces<a>today's news</a>
- The second argument is the
href
attribute value. For example,link_to("today's news", "www.news.com")
produces<a href="www.news.com">today's news</a>
- The third argument is a hash that contains everything else – most importantly, your
<a>
tag attributes. For example,link_to("today's news", "www.news.com", {id: "newsbox", class: "infos"})
produces<a id="newsbox" class="infos" href="www.news.com">today's news</a>
. The third argument can contain many other options, of which I have never been able to find a definitive list.