Class: TbRedirect

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/tb_redirect.rb

Class Method Summary collapse

Class Method Details

.create_smart(params) ⇒ Object



29
30
31
32
33
34
# File 'app/models/tb_redirect.rb', line 29

def self.create_smart(params)
  redirect = find_or_initialize_by(source: params.delete(:source))
  redirect.assign_attributes(params)
  redirect.save()
  return redirect
end

.find_with_uri(uri) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/tb_redirect.rb', line 17

def self.find_with_uri(uri)
  path = URI(uri).path
  uri_without_params = uri.split('?').first
  find_by(
    arel_table[:source].eq(path)
    .or(arel_table[:source].eq(uri_without_params))
  )
rescue URI::InvalidURIError => e
  logger.debug e.message
  return nil
end