Skip to content
Quick and configurable canonical tag to use in Rails views.
Ruby HTML JavaScript CSS
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
config Generated a Rails engine Apr 2, 2012
lib Patch version bump Jun 25, 2019
spec Recover spcs Feb 1, 2018
.gitignore setup appraisal May 25, 2016
.travis.yml Lock bundler to 1.x for older Ruby runtimes Jan 19, 2019
Gemfile Generated a Rails engine Apr 2, 2012
MIT-LICENSE Generated a Rails engine Apr 2, 2012 Remove outdated badge Aug 7, 2018
Rakefile Generated a Rails engine Apr 2, 2012
canonical-rails.gemspec Add Rails 6.0 support Jan 19, 2019


Build Status

A number of articles exist explaining the issue concisely and at length:


Take a look at this blog post that can guide you through the idea and the setup: Easily add canonical URLs to your Rails app


I've seen a lot of folks do more harm by neglecting canonicalization altogether than by applying too narrowly and conservatively, so here is an attempt to let people start modestly without spending too much time on it and whitelist parameters as they need to.


gem 'canonical-rails', github: 'jumph4x/canonical-rails'


First, generate the config

rails g canonical_rails:install

Then find it in config/initializers/ as canonical_rails.rb

Finally, include the canonical_tag helper inside the head portion of your HTML views:

  <%= canonical_tag -%>


A project by Downshift Labs, Ruby on Rails, Performance tuning and Spree Commerce projects.

You can’t perform that action at this time.