Alex Rivera | Logout

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

Asked 2010-09-23T20:48:30.670
10

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

Edit
Report

1 Answer

-5

Try something like that

def link_to_with_autotitle(title, args = {})
  link_to_without_autotitle(title, args.merge(:title => title))
end
alias_method_chain :link_to, :autotitle

Haven't tested the code and do not remember the exact link_to spec but I think you get the idea

answered 2010-09-24T17:01:32.877

Your Answer