forked from dusty/mongoid_grid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.txt
59 lines (37 loc) · 1.16 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Mongoid::Grid / Rack::Grid
Mongoid::Grid is a plugin for mongoid that uses GridFS. Heavily inspired
by grip (http://github.com/jnunemaker/grip)
Rack::Grid is used to serve a GridFS file from rack. Mostly copied
from http://github.com/skinandbones/rack-gridfs
Download the source at
http://github.com/dusty/mongoid_grid
Installation
Put the libraries in your project however you want.
You could make a gem to install or use with bundler.
# git clone http://github.com/dusty/mongoid_grid
# cd mongoid_grid
# gem build mongoid_grid.gemspec
Then require the libraries you want to use.
require 'mongoid/grid'
require 'rack/grid'
Usage
class Monkey
include Mongoid::Document
include Mongoid::Grid
field :name
attachment :image
end
m = Monkey.create(:name => 'name')
# To add an attachment
m.image = File.open('/tmp/me.jpg')
m.save
# To remove an attachment
m.image = nil
m.save
# To get the attachment
m.image.read
# To use Rack::Grid with Sinatra
configure do
use Rack::Grid, :database => 'my_db'
end
<img src="<%= m.image_url %>" alt="<%= m.image_name %>" />