In my app I will have an ad banner, but it won't be displayed on every page. So, I've defined the ad banner in application controller:
before_action :set_ad_banner
def set_ad_banner
@ad_banner = Advertising
.where('date_start_on <= ? AND date_end_on >= ?', Date.today, Date.today)
.order('RAND()')
.take
impressionist(@ad_banner)
end
I use impressionist
gem to see, how many times the ad has been displayed. But doing so, as it is set now, will count the impressions every time any of the pages are load, even if there is no content_for
tag with the banner. I also tried to move the code to the view, but this code: impressionist(@ad_banner)
doesn't work in the view. Any ideas how to solve this issue? Thanks.