Shamelessly lifted from this email from TobiasLuetke
Now, this will create three Image objects, right? So, if each image is 500KB, that’s at least a 1.5MB database transfer (right?). I really only need each image id.
I store my images in the database too but have a File model which has a belongs_to :binary
The binaries tables has the actual data, the File table has just the information about it (eg: format, mime, imagesize, filename etc )
This lets you use File as normal active record object and only receive the blob when needed over the binary relation.
Also see Caching images in Rails for a clever way to avoid performance hits when using a database to store images (and files).