Module: ImageHelper

Overview

typed: ignore

Instance Method Summary collapse

Instance Method Details

#fix_image_url(url, only_path = false) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/image_helper.rb', line 3

def fix_image_url(url, only_path = false)
  return url if only_path

  return url if url.to_s.include?('http')

  # has no hostname
  host = if Figaro.bool_env! :ENABLE_CDN
           is_skip_host = RequestStore.store[:skip_host]
           cdn_url = Figaro.env.CDN_URL!
           if is_skip_host.nil?
             cdn_url
           elsif is_skip_host
             ''
           else
             cdn_url
           end
         elsif Rails.env.production?
           _default_host
         else
           ''
         end

  "#{host}#{url}"
end