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



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

Instance Method Details

#_list_item_subtitleObject



36
37
38
# File 'app/models/redirect.rb', line 36

def _list_item_subtitle
  'Created ' + ActionController::Base.helpers.time_ago_in_words(created_at) + ' ago'
end

#_list_item_titleObject

Helpers



31
32
33
# File 'app/models/redirect.rb', line 31

def _list_item_title
  path_from
end

#ascObject

Scope



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

default_scope -> { asc(:path_from) }

#path_fromObject

Search



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

field :path_from, type: String