# Advice on Best Approach

**URL:** <https://www.ruby-forum.com/t/advice-on-best-approach/133287>\
**Category:** Rails\
**Created:** [March 29, 2008, 7:24pm UTC](https://www.ruby-forum.com/t/advice-on-best-approach/133287 "2008-03-29T19:24:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacobly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/4da419/32.png) [@jacobly](https://www.ruby-forum.com/u/jacobly)\
**Post date:** [March 29, 2008, 7:24pm UTC](https://www.ruby-forum.com/t/advice-on-best-approach/133287/1 "2008-03-29T19:24:55Z")

</div>

I’m creating a very simple photography portfolio site. I would like to  
set this up so that my application recognizes and pulls photos from a  
given directory (images folder) automatically. This way the entire  
site’s images can be maintained by simply adding and removing via ftp.

What’s the simplest way to go about this? Do I need an xml file? Please  
be as specific as possible and thank you! in advance.

(In the end, I plan on having a directory for each of the categories…  
portraits, landscape, wedding, etc.)

---

<div class="post-metadata">

**Author:** ![jacobly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/4da419/32.png) [@jacobly](https://www.ruby-forum.com/u/jacobly)\
**Post date:** [March 29, 2008, 7:37pm UTC](https://www.ruby-forum.com/t/advice-on-best-approach/133287/2 "2008-03-29T19:37:41Z")

</div>

You can just read all the files in the directory and create image tags  
for them dynamically. If you give the filenames good descriptive names  
you won’t have to hard-code anything, either.

For example, if you have “House Next to Lake.jpg”, “Sunset in Santa  
Cruz.jpg”, etc., you can then do something like:

\<% for image\_path in Dir.entries(path\_to\_images) -%\>  
\<%= image\_tag image\_path %\>  
  
\<%= image\_path[/(.+)./,1]  
\<% end %\>

If you want the images in a specific order you could pre-pend a number  
to each image filename, sort the list of images, and then just strip  
it off with the regex.

HTH,

Matt

On Mar 29, 12:24 pm, Jacob L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
