Class: Refinery::Redirections::Redirection

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
Enumerize
Defined in:
app/models/refinery/redirections/redirection.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sanitize_path(path, ignored_path_params = Refinery::Redirections.ignored_path_params) ⇒ Object

This method gets a path and ‘sanitizes it’. This means that all the params that we don’t want (Google Analytics params, testing params…) are stripped out and params are sorted so ‘/en?a=1&b=1’ and ‘/en?b=1&a=1’ are the same



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/refinery/redirections/redirection.rb', line 19

def self.sanitize_path path, ignored_path_params = Refinery::Redirections.ignored_path_params
  path, params = path.split("?")
  if params.blank?
    path
  else
    # We split the params
    params = params.split('&')
    # And then get those ignored and remove them
    not_ignored_params = params.reject{|p| ignored_path_params.detect{|ignored| p.start_with?("#{ignored}=") || (p == ignored)}}

    not_ignored_params.blank? ? path : "#{path}?#{not_ignored_params.sort.join('&')}"

  end

end

Instance Method Details

#sanitize_pathObject



12
13
14
# File 'app/models/refinery/redirections/redirection.rb', line 12

def sanitize_path
  self.from_url = self.class.sanitize_path from_url
end

#titleObject



35
36
37
# File 'app/models/refinery/redirections/redirection.rb', line 35

def title
  "#{from_url} -> #{to_url} (#{status_code})"
end