SEO/Rails - How to add the title tag to every "link_to"

Alextoul picture Alextoul · Sep 23, 2010 · Viewed 11.7k times · Source

I'm surprised Rails creator didn't think about that, if someone can help, would be great.

How can we do to change this:

<%= link_to "My Title", :controller => "products" %>

to this automatically:

<%= link_to "My Title", :controller => "products", :title => "My Title" #basically a copy of the text %>

I think it could help SEO a lot.

Thanks a lot!

Alex

Answer

Abram picture Abram · May 11, 2014

This is the rails 3 way:

<%= link_to object_path, title: "Path Title" %>

Further reading: https://www.searchenginejournal.com/how-to-use-link-title-attribute-correctly/