jumph4x/canonical-rails

Check if url is canonical?

molfar opened this issue · 4 comments

Is there any helper to detect if current url is canonical or not?

Consider creating your own helper method leveraging https://github.com/jumph4x/canonical-rails/blob/master/app/helpers/canonical_rails/tag_helper.rb#L44, something similar to this:

def canonical? path
   path == canonical_path
end

or

def current_path_canonical? 
   request.path == canonical_path
end

@jumph4x thanks. May be it would be expedient to include it in gem? For example, my case is implementing Google's recommendation to include rel alternates links to only canonical pages.

UPD request.path doesnt work as expected. Instead request.fullpath is raw path with query string

I am hesitant to include extra functionality that the gem itself does not already use. Comment with the documentation/guidelines here and I can do a longer think on it.

I'm sure this existing in closed issues will help someone out looking to replicate this request, thank you for submitting. Closing.