Class: Redirect

Inherits:
Object
  • Object
show all
Includes:
Ants::Id, Mongoid::Document, Mongoid::Search, Mongoid::Timestamps
Defined in:
app/models/redirect.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ants::Id

#serializable_hash

Class Method Details

.match(request) ⇒ Object

Class Methods



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/redirect.rb', line 37

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

Instance Method Details

#_list_item_titleObject

Helpers



28
29
30
# File 'app/models/redirect.rb', line 28

def _list_item_title
  "#{path_from}#{path_to}"
end

#ascObject

Scope



19
# File 'app/models/redirect.rb', line 19

default_scope -> { asc(:path_from) }

#path_fromObject

Search



8
# File 'app/models/redirect.rb', line 8

field :path_from, type: String