Forum: Ruby on Rails ActiveRecord and Images

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7cdce9e94d317c4f0a3dcc20cc3b4115?d=identicon&s=25 Nicholas Wieland (Guest)
on 2006-03-08 02:45
(Received via mailing list)
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 Wieland
nicholas_wieland@yahoo.it





___________________________________
Yahoo! Messenger with Voice: chiama da PC a telefono a tariffe esclusive
http://it.messenger.yahoo.com
C941170ba5ca038b89b8407c83fb23c2?d=identicon&s=25 Berin Loritsch (Guest)
on 2006-03-08 05:09
(Received via mailing list)
Nicholas Wieland 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:

http://jroller.com/page/bloritsch?entry=saving_ima...

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.
7cdce9e94d317c4f0a3dcc20cc3b4115?d=identicon&s=25 Nicholas Wieland (Guest)
on 2006-03-08 10:59
(Received via mailing list)
Il giorno 08/mar/06, alle ore 05:08, Berin Loritsch ha scritto:

> CUT

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


--
Nicholas Wieland
nicholas_wieland@yahoo.it








___________________________________
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB
http://mail.yahoo.it
Ba3a00606eb530dcab2c4a6a59bf366d?d=identicon&s=25 Alain Ravet (Guest)
on 2006-03-08 14:11
(Received via mailing list)
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
This topic is locked and can not be replied to.