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
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/
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With