Post Archive

› November 30, 2005

Rapid to Reproduce Random Rotator for Ruby on Rails

  • Reported by Nate

Dan Benjamin, system developer of the powerhouse new A List Apart site among many other things, has shared a little morsel of Ruby-On-Rails goodness for those who've adopted the framework. It's his classic image rotator ala rails and its ridiculously short.

Comments

1. November 30, 2005 06:44 PM

Quote this comment

riffraff Posted…

Actually, I think he can avoid some code like this:

def rand_img 
 files=Dir['*.{jpg,gif,png}'] 
 files[rand(f.length)] 
end
Too bad there isn0t an Enumerable#rand :)

2. November 30, 2005 06:57 PM

Quote this comment

riffraff Posted…

emh.. obviously f.length should be files.length

3. January 6, 2006 03:51 AM

Quote this comment

Dan Posted…

How would the code look if you were pulling image urls from a database?

4. April 11, 2006 04:22 PM

Quote this comment

Garbich Posted…

Super!