Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

29 lines (19 sloc) 1.277 kB

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:

/images/grid_image/resize_100x100_[path_to_grid_fs_file]

How to use

  1. 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

  2. Copy grid_image.rb to your projects lib directory

  3. Create (if you do not already have one) a metal directory in your projects app directory
  4. Copy grid_file.rb to app/metal in your project directory.
  5. Restart your rails app
  6. Ensure you have added a file into your mongo database, then point your browser to: http:///images/grid_file/

Notes

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.

Jump to Line
Something went wrong with that request. Please try again.