Rails Metal for serving images from GridFS
The metal file catches routes for /images/grid_image/[path_to_grid_fs_file].
It also handles resizing using the following pattern:
How to use
Install the dependencies: gem install RubyInline image_science mongo_mapper (you may need to install FreeImage - see the ImageScience website: http://seattlerb.rubyforge.org/ImageScience.html
Copy grid_image.rb to your projects lib directory
- Create (if you do not already have one) a metal directory in your projects app directory
- Copy grid_file.rb to app/metal in your project directory.
- Restart your rails app
- Ensure you have added a file into your mongo database, then point your browser to: http:///images/grid_file/
This library assumes you are using MongoMapper for your database layer - if you are not you will need to jump into the code and a) remove the reference to the mongo initalizer file, and b) change the way that the lib gets the database handle.
I would recommend sticking with MongoMapper, and using Joint as a plugin in your MM Documents to simplify attachments.