Posted in Knowledge
Here are some rails-way tips on SEO. Please share me your tips because there is always more than one way to do something when it comes to Ruby.
Create unique, accurate page titles
A title tag tells what the topic of a page is. You should create a unique title for each page on your site. Beside title, you sould also set the description for meta tag as well.
You use content_for to achieve this.
In your view you can do
<% content_for :title, 'New Task' %>
<% content_for :description, 'Create a task' %>
<h1><%= yield :title %></h1>
and in your layout
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title><%= yield(:title) || "Task Manager: #{controller.action_name}" %></title>
<%= tag(:meta, :name => 'description', :content => yield(:description) || "A Task Manager application for everyone") %>
Prettier URL
If you your site is a blog then you should handle your permalinks easy with PermalinkFu.
As time goes by, you site grows and sometimes your URL is changes too. You should make that the old links are redirected properly
def old_show
redirect_to params.merge(:action => :show), :status => :moved_permanently
end
Information on images
Always set :alt on your image tag
<%= image_tag photo.url, :alt => "My vacation" %>
Make use of “noffollow”
Some search engine doesn’t follow links that have attribute rel=”nofollow”, while some other follows but exclude it from their ranking calculation.
You should use this attribute for links inside blog comments or other user generated content.
<%= auto_link(h(comment.body), :all, :rel => "nofollow") %>
Canonical URL Tag
The new “canonical url tag” are exist to help site owners eliminate self-created duplicate content. The tag is part of the HTML header and use like below
<link href="http://www.myawesomewebapps.org/blog" rel="canonical" />
You can easily add it in the head of your layout
<%= yield :canonical %>
and a simple helper in application_helper.rb:
def canonical(url)
%Q|<link name="canonical" href="#{url}" >|
end
and add this to any template view
<% content_for :canonical do %>
<%= canonical("http://www.myawesomewebapps.org/tasks") %>
<% end %>