Hi, i try to figure out the solution for simple banner ad script. I've db table 'banners' with fields 'id', 'image', and 'url'. I suppose to keep in this table 5 banners, so the ids are always from 1 to 5. I just wont to loop from 1 to 5 and show appropriate banner, in header layout (not view).
At this time i put the banner into layout's header with direct query to db using Banner model:
*banner.rb* class Banner < ActiveRecord::Base def self.banner @banner = Banner.find(:first, :conditions => ['date_end > ?', Time.now.strftime("%Y-%m-%d %H:%M:%S")]) @banner.nil? ? "adimage.gif" : @banner.image end
*layout.rhtml* <div id="headerbanner"> <%= image_tag(Banner.banner) %> </div>
I think i must increment some variable in layout.rhtml and return this to Banner model. Or there is a better way? Thanks in advance