First I assumed, that the quantity of images in table will be
But later the problem has become complicated ( for me as newbie ),
because I’ve added the field ‘date_end’, so that banner can expire.
It means, that the quantity of images varies, and a very simple
looping through id in table does not give the solution.
Because as result of executing code
@banners = Banner.find(@counter, :conditions => [‘date_end > ?’,
i has error like ‘Could not find record with id = X and Date_end >
I tried @banners.nil? and similar statements (blank, empty), but with
no success. I think, this is because the error occures before the
@banners became some value or nil at all.
As my first post says, banners table has fields ‘id’, ‘image’, and
At this time process works this way:
in environment.rb i’ve added the Counter class as Peter E.
@@counter = 0
@@counter += 1
@@counter = 1
in controller that manages banners:
@counter = Counter.increment_cnt
@banners = Banner.find(:all,
:conditions => [‘date_end > ?’, Time.now.strftime("%Y-%m-%d %H:%M:
if @counter > @banners.size then
@counter = 1
[[@banners[@counter-1].image] , [@banners[@counter-1].url]]
<% banner = BannersController.banner %>
<%= link_to image_tag(banner.to_s ), banner.to_s %>
So, this way i do not loop through ids of records in tables, but
through elements of @banners array. Elements are in fact ActiveRecord
objects, it doesn’t matter what ids they had