# Is ruby only usable for pictures not for documents?

**URL:** <https://www.ruby-forum.com/t/is-ruby-only-usable-for-pictures-not-for-documents/169450>\
**Category:** Ruby\
**Created:** [June 3, 2009, 9:39pm UTC](https://www.ruby-forum.com/t/is-ruby-only-usable-for-pictures-not-for-documents/169450 "2009-06-03T21:39:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pink-ink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pink-ink](https://www.ruby-forum.com/u/pink-ink)\
**Post date:** [June 3, 2009, 9:39pm UTC](https://www.ruby-forum.com/t/is-ruby-only-usable-for-pictures-not-for-documents/169450/1 "2009-06-03T21:39:39Z")

</div>

Hi Ruby-Community,

I searched the last days a lot for finding a plugin or tutorial for  
storing documents (like pdf, doc, dox, with mime-type etc.) into the  
database, the only thing I found was plugins or howtos for storing  
pictures (attachment\_fu etc.).

Normally when you try to develop professional solutions you have to  
store documents like contracts etc. and something else into the  
database.

But it looks like, that RoR is only good for storing pictures, do  
sombody knows howt to store \*.pdf, \*.docs etc. into the database? Maybe  
with full-text-indexing?

Thanks ahead,

Regs

Herman

---

<div class="post-metadata">

**Author:** ![pink-ink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pink-ink](https://www.ruby-forum.com/u/pink-ink)\
**Post date:** [June 3, 2009, 10:06pm UTC](https://www.ruby-forum.com/t/is-ruby-only-usable-for-pictures-not-for-documents/169450/2 "2009-06-03T22:06:21Z")

</div>

On Wed, Jun 3, 2009 at 12:39 PM, Herman Müller [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Normally when you try to develop professional solutions you have to  
> store documents like contracts etc. and something else into the  
> database.

Well, you have to store them _somewhere_. I’d argue that the database  
is not a very good fit. You can’t query against a blob.

> But it looks like, that RoR is only good for storing pictures, do  
> sombody knows howt to store \*.pdf, \*.docs etc. into the database? Maybe  
> with full-text-indexing?

Generally it’s better to store the files on the filesystem and paths  
in the database. As for indexing, you’ll need to devise a method to  
extract meaningful data from your documents and store that data in the  
database.

Ben

---

<div class="post-metadata">

**Author:** ![pink-ink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pink-ink](https://www.ruby-forum.com/u/pink-ink)\
**Post date:** [June 3, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/is-ruby-only-usable-for-pictures-not-for-documents/169450/3 "2009-06-03T22:30:40Z")

</div>

On Jun 3, 1:39 pm, Herman Müller [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Ruby-Community,

Hi.

> I searched the last days a lot for finding a plugin or tutorial for  
> storing documents (like pdf, doc, dox, with mime-type etc.) into the  
> database, the only thing I found was plugins or howtos for storing  
> pictures (attachment\_fu etc.).

attachment\_fu can store whatever you give it. The examples for the  
has\_attachment method includes ones like: has\_attachment :content\_type  
=\> ‘application/pdf’

> But it looks like, that RoR is only good for storing pictures, do  
> sombody knows howt to store \*.pdf, \*.docs etc. into the database?

Ruby on Rails has no intrinsic issue with storing PDFs in a database,  
or any intrinsic strength for storing images. I’d suggest reading the  
documentation for attachment\_fu to see how to do it.

HTH,  
Chris

---

<div class="post-metadata">

**Author:** ![pink-ink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pink-ink](https://www.ruby-forum.com/u/pink-ink)\
**Post date:** [June 3, 2009, 10:35pm UTC](https://www.ruby-forum.com/t/is-ruby-only-usable-for-pictures-not-for-documents/169450/4 "2009-06-03T22:35:58Z")

</div>

On Wed, Jun 3, 2009 at 4:30 PM, Chris S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ruby on Rails has no intrinsic issue with storing PDFs in a database,  
> or any intrinsic strength for storing images. I’d suggest reading the  
> documentation for attachment\_fu to see how to do it.

Maybe we should ship Prawn with an Sqlite database? 😉

---

<div class="post-metadata">

**Author:** ![pink-ink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pink-ink](https://www.ruby-forum.com/u/pink-ink)\
**Post date:** [June 4, 2009, 3:56am UTC](https://www.ruby-forum.com/t/is-ruby-only-usable-for-pictures-not-for-documents/169450/5 "2009-06-04T03:56:04Z")

</div>

Ben B. wrote:

> On Wed, Jun 3, 2009 at 12:39 PM, Herman Müller [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Normally when you try to develop professional solutions you have to  
> > store documents like contracts etc. and something else into the  
> > database.
> 
> Well, you have to store them _somewhere_. I’d argue that the database  
> is not a very good fit. You can’t query against a blob.

The database is not a good fit for large binary files because databases  
and  
filesystems are architected and tuned for completely different  
performance  
envelops. Databases work best relating long lists of short data.  
Filesystems  
work best manipulating short directories of huge files.

Further, a web server can serve those files without bothering Ruby.  
'nuff said!

Put your documents on the filesystem and store their paths in your  
database. The  
Rails plugin called Paperclip shows how to do this, with a system that  
would be  
very hard to improve on.

---

<div class="post-metadata">

**Author:** ![pink-ink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pink-ink](https://www.ruby-forum.com/u/pink-ink)\
**Post date:** [June 4, 2009, 12:11am UTC](https://www.ruby-forum.com/t/is-ruby-only-usable-for-pictures-not-for-documents/169450/6 "2009-06-04T00:11:02Z")

</div>

On 03.06.2009 22:05, Ben B. wrote:

> On Wed, Jun 3, 2009 at 12:39 PM, Herman Müller [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Normally when you try to develop professional solutions you have to  
> > store documents like contracts etc. and something else into the  
> > database.
> 
> Well, you have to store them _somewhere_. I’d argue that the database  
> is not a very good fit. You can’t query against a blob.

A database gives you a few things which may be important for some  
projects

- it is transactional, e.g. you can do safe updates in concurrency  
situations and you can make sure that a set of changes is done  
atomically. This helps keeping application data consistent.

- you have all your application data in one place,

- which is especially useful for backups; RDBMS usually come with some  
form of backup solution, some of those are even capable of doing hot  
backups, i.e. while the application is active.

- professional databases come with a lot more features that can be  
important for a business (replication, security…).

> > But it looks like, that RoR is only good for storing pictures, do  
> > sombody knows howt to store \*.pdf, \*.docs etc. into the database? Maybe  
> > with full-text-indexing?
> 
> Generally it’s better to store the files on the filesystem and paths  
> in the database. As for indexing, you’ll need to devise a method to  
> extract meaningful data from your documents and store that data in the  
> database.

That extraction and indexing part can be done by some databases for some  
document types (full text indexing, features for spatial data). Of  
course, you pay a price when you place documents in the database  
(license fees, no direct access to docs) but one should be aware of the  
options.

Kind regards

robert
