Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 846
Alextoul Avatar asked Sep 23 '10 20:09

Alextoul


2 Answers

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/

like image 125
Abram Avatar answered Nov 02 '22 23:11

Abram


Your question is valid and I don't know why you are down-voted, but, the creator of rails DID actually think about this. Actually, you can do it in a very simple manner instead of complicating using a custom method:

<%= link_to "Link", { :action => "show" }, { :title => "Title" } %>

You can in fact add any parameter you like, not just the title.

Hope this helps!

like image 45
dsignr Avatar answered Nov 02 '22 23:11

dsignr