Skip to content

Instantly share code, notes, and snippets.

@ehoch
Last active December 11, 2015 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehoch/4637369 to your computer and use it in GitHub Desktop.
Save ehoch/4637369 to your computer and use it in GitHub Desktop.
Alarm Grid, a home security store, shows you how to set canonical urls in Spree.
- if @canonical_url
= tag('link', :rel => 'canonical', :href => "http://" + Spree::Config[:site_url] + URI.parse(@canonical_url).path)

Alarm Grid will show you how to create canonical urls in Spree Commerce. This is only an example for products show. You must implement EVERYWHERE.

Deface::Override.new(:virtual_path => 'spree/layouts/spree_application',
:name => 'canonical_url',
:insert_bottom => "[data-hook='inside_head']",
:partial => 'shared/canonical_url')
module Spree
ProductsController.class_eval do
before_filter :show_filter, :only => :show
def show_filter
@canonical_url = spree.product_path(:id => @product.permalink)
end
end
end
@samhamilton
Copy link

Spree 2.0.4 now includes https://github.com/jumph4x/canonical-rails by default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment