Method: Redirect.match

Defined in:
app/models/redirect.rb

.match(request) ⇒ Object

Class Methods



42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/redirect.rb', line 42

def self.match(request)
  # request.fullpath includes parameters and leading / so
  # add ending slash (Rails skips it) as alternative option
  fullpath      = request.fullpath.downcase
  fullpath_alt1 = fullpath.gsub('?', '/?')

  # decode URL to UTF string, e.g. %C3%A9 => é
  fullpath_alt2 = URI.unescape(fullpath)
  fullpath_alt3 = URI.unescape(fullpath_alt1)

  self.where(:path_from.in => [ fullpath, fullpath_alt1, fullpath_alt2, fullpath_alt3 ]).first
end