I have a method that gets a random banner, but I do not want it to show the same banner twice in a row.
def random_banner
@koder = @side.reklamers.all(:select => :id).collect(&:id)
@koder.sample gets a random ID
@reklame = Reklamer.find(@koder.sample)
render :text => @reklame.kode
end
What is the best solution?
TDGS solution:
When I visit the action, it works well, but I have a blog that makes an ajax call to get the banner code, and there, the same banner appear twice in a row.
Store the last used banner id in the session somewhere, say
session[:banner_id]Then, do the following: