Image Files

I'm a Rails newby and I'm in the process of creating my first Rails app - a knock-off of IMDb, albeit a 'nano' version of it.

When displaying the details of a movie I would like to show the movie's (DVD) cover art. How do I store images in my sqlite3 database? Should the (database) column be of type BINARY? Is there a Rails helper for uploading images via web page form?

Hope the above makes some sense to somebody.

Thanks Steve

Marnen Laibow-Koser wrote:

No. Image data does not belong in the DB. Put it in the filesystem instead, and just store the filename in a text field in the DB.

The reason is simply so the webserver can serve images directly off the file system without touching any Ruby code.

There's the Paperclip plugin, and also attachment_fu. I've never used either, but more people seem to like Paperclip.

I worked for 2.5 years on a project that reproduced Paperclip from scratch (I got there just after the crew migrated the images _out_ of the database!), and now I would never serve images without it.

Now to your question. Sqlite is inappropriate for production, and you probably shouldn't really be using it for development. Use a real DB (I recommend PostgreSQL).

This is my first app, so it's not intended for production. Using Sqlite because as a newby that's one less thing to worry about. As an Ingres developer I have to recommend Ingres as the open source database of choice (though I don't pretend to know how well it currently works with Rails).

No. Image data does not belong in the DB. Put it in the filesystem instead, and just store the filename in a text field in the DB.

Right. I'm embararssed I asked that question.

There's the Paperclip plugin, and also attachment_fu. I've never used either, but more people seem to like Paperclip.

Thanks

Why is the image "the_godfather.jpg" not being displayed, considering the following show view template? Or even when I include the full absolute path?

<p>   <%= "#{@movie.rank}. #{@movie.title}" %> </p> <p>   <%= "Director: #{@movie.director}" %> </p> <p>   <%= "Release Date: #{@movie.release_date.to_date.to_formatted_s (:long_ordinal)}" %> </p> <p>   <%= "Plot: #{@movie.plot}" %> </p> <img src="public/images/the_godfather.jpg" />

because the document root is public: that path should be /images/ the_god_father.jpg

Rred

Too easy, thanks!

shusseina wrote: [...]

This is my first app, so it's not intended for production. Using Sqlite because as a newby that's one less thing to worry about.

I'm not sure it's one less thing to worry about. Setup may be easier, but I gather that SQLite (which I've never used, so take this for what it's worth) will run you into a wall with its limited query syntax and nonexistent concurrency support.

As an Ingres developer I have to recommend Ingres as the open source database of choice (though I don't pretend to know how well it currently works with Rails).

I didn't even know the Ingres project was still alive! What can Ingres offer a Rails developer that PostgreSQL cannot? It would be interesting to know.

Best,