Class: Spree::Frontend::Middleware::SeoAssist

Inherits:
Object
  • Object
show all
Defined in:
lib/spree/frontend/middleware/seo_assist.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ SeoAssist

Returns a new instance of SeoAssist.



6
7
8
# File 'lib/spree/frontend/middleware/seo_assist.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/spree/frontend/middleware/seo_assist.rb', line 10

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