Class: Spree::Frontend::Middleware::SeoAssist
- Inherits:
-
Object
- Object
- Spree::Frontend::Middleware::SeoAssist
- Defined in:
- lib/spree/frontend/middleware/seo_assist.rb
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.
8 9 10 |
# File 'lib/spree/frontend/middleware/seo_assist.rb', line 8 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/spree/frontend/middleware/seo_assist.rb', line 12 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, "#{request.script_name}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 |