Author and Canonical Link for SEO in Rails Apps

Introduction

In this article we will add the author meta tag and canonical link for article. You can read the articles in the references section at the end of this article to learn why we need them. The first 100 articles or so on rubyplus.com used only integer in the URL for showing an article, I later made the URL use permalink to make it easy for me to identify which articles is most popular when I saw the Google Analytics. The most popular articles became screencasts.

Implementation for Rails

In articles/show.html.erb, provide the value for the author meta tag and canonical link as follows:

<%= content_for(:meta_author, 'Bala Paranj') %>
<%= content_for(:canonical_link, article_url(@article)) %>

<article>
<h1 class="content-header"><%= @article.title %></h1>
  <div class="byline">
      <address class="author">By <a rel="author" href="/about">Bala Paranj</a></address><time pubdate datetime="<%= published_date(@article) %>" title="<%= published_date(@article) %>"> <%= published_date(@article) %>  </time>
  </div>          
</div>

...

</article>

Each article is wrapped within article html tag. Also the header must have header tag. I have not used header tag above due to styling issues in my app. In application layout file:

<% if yield(:meta_author).present? %>
  <meta name="author" content="Bala Paranj" />
<% end %>

<% if yield(:canonical_link).present? %>
  <link rel="canonical" href="<%= yield(:canonical_link) %>" >
<% end %>

References

Dynamic SEO Title and Meta Tags in Rails
Canonical Link
HTML 5 Tags to Use for Author Name
Microformats


Related Articles


Ace the Technical Interview

  • Easily find the gaps in your knowledge
  • Get customized lessons based on where you are
  • Take consistent action everyday
  • Builtin accountability to keep you on track
  • You will solve bigger problems over time
  • Get the job of your dreams

Take the 30 Day Coding Skills Challenge

Gain confidence to attend the interview

No spam ever. Unsubscribe anytime.