Class: Redirect
- Inherits:
-
Object
- Object
- Redirect
- Includes:
- Ants::Id, Mongoid::Document, Mongoid::Search, Mongoid::Timestamps
- Defined in:
- app/models/redirect.rb
Class Method Summary collapse
-
.match(request) ⇒ Object
Class Methods.
Instance Method Summary collapse
-
#_list_item_title ⇒ Object
Helpers.
-
#asc ⇒ Object
Scope.
-
#path_from ⇒ Object
Search.
Methods included from Ants::Id
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_title ⇒ Object
Helpers
28 29 30 |
# File 'app/models/redirect.rb', line 28 def _list_item_title "#{path_from} → #{path_to}" end |
#asc ⇒ Object
Scope
19 |
# File 'app/models/redirect.rb', line 19 default_scope -> { asc(:path_from) } |
#path_from ⇒ Object
Search
8 |
# File 'app/models/redirect.rb', line 8 field :path_from, type: String |