Class: SeoAssist
- Inherits:
-
Object
- Object
- SeoAssist
- Defined in:
- lib/middleware/seo_assist.rb
Overview
Make redirects for SEO needs
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ SeoAssist
constructor
A new instance of SeoAssist.
Constructor Details
#initialize(app) ⇒ SeoAssist
Returns a new instance of SeoAssist.
3 4 5 |
# File 'lib/middleware/seo_assist.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/middleware/seo_assist.rb', line 7 def call(env) request = Rack::Request.new(env) params = request.params taxon_id = params['taxon'] #redirect requests using taxon id's to their permalinks if !taxon_id.blank? && !taxon_id.is_a?(Hash) && taxon = Taxon.find(taxon_id) params.delete('taxon') return build_response(params, "/t/#{taxon.permalink}" ) elsif env["PATH_INFO"] =~ /^\/(t|products)(\/\S+)?\/$/ #ensures no trailing / for taxon and product urls return build_response(params, env["PATH_INFO"][0...-1]) end @app.call(env) end |