Module: EffectiveBannerAdsHelper

Defined in:
app/helpers/effective_banner_ads_helper.rb

Instance Method Summary collapse

Instance Method Details

#effective_banner_adsObject



5
6
7
# File 'app/helpers/effective_banner_ads_helper.rb', line 5

def effective_banner_ads
  @_effective_banner_ads ||= Effective::BannerAd.published.deep.all
end

#render_banner_ad(location, opts = {}, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/effective_banner_ads_helper.rb', line 9

def render_banner_ad(location, opts = {}, &block)
  location = EffectivePages.banner_ads.find { |obj| obj == location }
  raise("unknown banner ad location: #{location.presence || 'nil'}. Please add it to EffectivePages.banner_ads config option") if location.blank?

  banner_ads = effective_banner_ads.select { |ba| ba.location == location }
  return if banner_ads.blank?

  # Choose a random banner ad
  banner_ad = banner_ads.sample

  if block_given?
    yield(banner_ad); nil
  else
    render('effective/banner_ads/banner_ad', banner_ad: banner_ad, banner_ad_opts: opts)
  end
end