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_subtitle ⇒ Object
-
#_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
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_subtitle ⇒ Object
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_title ⇒ Object
Helpers
31 32 33 |
# File 'app/models/redirect.rb', line 31 def _list_item_title path_from end |
#asc ⇒ Object
Scope
20 |
# File 'app/models/redirect.rb', line 20 default_scope -> { asc(:path_from) } |
#path_from ⇒ Object
Search
9 |
# File 'app/models/redirect.rb', line 9 field :path_from, type: String |