Module: Spree::CanonicalUrlHelper

Defined in:
app/helpers/spree/canonical_url_helper.rb

Instance Method Summary collapse

Instance Method Details

#canonical_href(host = nil) ⇒ String

Returns the full canonical URL for the current request

Parameters:

  • host (String) (defaults to: nil)

    The host/domain to use (defaults to request host)

Returns:

  • (String)

    The full canonical URL



15
16
17
18
# File 'app/helpers/spree/canonical_url_helper.rb', line 15

def canonical_href(host = nil)
  host ||= request.host
  "#{request.protocol}#{host}#{canonical_path}"
end

#canonical_pathString

Returns the canonical path for the current request (without query parameters)

Returns:

  • (String)

    The canonical path



23
24
25
# File 'app/helpers/spree/canonical_url_helper.rb', line 23

def canonical_path
  request.path.presence || '/'
end

#canonical_tag(host = nil) ⇒ ActiveSupport::SafeBuffer

Generates a canonical link tag for the current page

Parameters:

  • host (String) (defaults to: nil)

    The host/domain to use (defaults to current store’s domain)

Returns:

  • (ActiveSupport::SafeBuffer)

    The canonical link tag HTML



7
8
9
# File 'app/helpers/spree/canonical_url_helper.rb', line 7

def canonical_tag(host = nil)
  tag.link(href: canonical_href(host), rel: :canonical)
end