# ActiveRecord and Images

**URL:** <https://www.ruby-forum.com/t/activerecord-and-images/54541>\
**Category:** Rails\
**Created:** [March 8, 2006, 2:45am UTC](https://www.ruby-forum.com/t/activerecord-and-images/54541 "2006-03-08T02:45:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [March 8, 2006, 2:45am UTC](https://www.ruby-forum.com/t/activerecord-and-images/54541/1 "2006-03-08T02:45:22Z")

</div>

Not really a Rails question, but a “best practices” one.  
If I want to associate an image to every account in my application,  
is it better to insert the image file directly inside the db or to  
upload the image in public/images/ ?  
Also, if I want to associate a cover to a movie, what’s the best  
approach ?

## TIA, ngw

Nicholas W.  
removed\_email\_address@domain.invalid

* * *

Yahoo! Messenger with Voice: chiama da PC a telefono a tariffe esclusive

> **[Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos](https://www.yahoo.com/)**
>
> Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!

---

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [March 8, 2006, 5:09am UTC](https://www.ruby-forum.com/t/activerecord-and-images/54541/2 "2006-03-08T05:09:41Z")

</div>

Nicholas W. wrote:

> Not really a Rails question, but a “best practices” one.  
> If I want to associate an image to every account in my application, is  
> it better to insert the image file directly inside the db or to upload  
> the image in public/images/ ?  
> Also, if I want to associate a cover to a movie, what’s the best  
> approach ?  
> As with all good design question the answer is, “it depends”

Most of the file upload plugins and help you find for Rails is built  
around the filesystem, so for ease of use sake that makes sense. If you  
want a guide for how to work directly with the database I posted  
instructions on my blog here:

> **[Best Online Casino in Australia | Top Licensed Casinos for Gamblers](https://toponlinecasinoaustralia.com?entry=saving_images_to_the_database)**
>
> Best Online Casino in Australia with licensed games only. Play blackjack, roulette, poker and other top-notch casino games. Enjoy gambling 24/7.

Now, to answer your question. The whole “it depends” answer hinges on  
how you plan on growing. The Rails model of growth is to add more  
machines to handle the load. It’s a reasonable way to go, as evidenced  
by Google, Yahoo, etc. As you add more boxes you need to get at the  
images.

If you stored your images in the database, as your ISP handles upgrading  
the database (usually with a SAN or something) you have to change  
nothing. It’s all there, ready and waiting.

If you stored your images in the filesystem, you have a new challenge.  
Either you need to use a networked drive to house the application and  
let other machines read that drive, or you need to use a SAN for the  
application. The issue here is throughput. If you have a dozen  
machines all trying to read and write files from one, then you have a  
serious bottleneck.

In reality, by the time you need to start distributing load across  
multiple machines a SAN is probably in your near future. (SAN: Storage  
Area Network) Whether its for the database or the file system, SANs can  
distribute your storage needs across multiple physical locations and  
look like one really huge drive. All of the clustering and distributing  
is done behind the scenes.

My personal opinion is that storing the images in the database gives me  
that extra level of security blanket feeling. Its transactional (with  
the exception of certain legacy table types in MySQL), which means I  
never get a partially saved file. It’s also usually easy to back up and  
restore as those are functions are built into the database anyway.  
Lastly, all my data is in one place so it makes it easier for me to  
manage. As with all things YMMV.

---

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [March 8, 2006, 10:59am UTC](https://www.ruby-forum.com/t/activerecord-and-images/54541/3 "2006-03-08T10:59:03Z")

</div>

Il giorno 08/mar/06, alle ore 05:08, Berin L. ha scritto:

> CUT

Thank you very much, everything is much more clear now.

–  
Nicholas W.  
removed\_email\_address@domain.invalid

* * *

Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB  
[http://mail.yahoo.it](http://mail.yahoo.it)

---

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [March 8, 2006, 2:11pm UTC](https://www.ruby-forum.com/t/activerecord-and-images/54541/4 "2006-03-08T14:11:15Z")

</div>

Nicholas,

- Next to what Berin told you, the simple/Rails way is to 1°/store  
images in the file system with 2°/ the file\_column plugin.
- As you’re asking for “best practices”, if you don’t have the user  
picture for a given account, I’d go for displaying a silhouette rather  
than showing a blank frame.

Alain
