mongoid-paperclip 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +23 -17
- data/lib/mongoid_paperclip.rb +8 -1
- data/{mongoid_paperclip.gemspec → mongoid-paperclip.gemspec} +3 -3
- metadata +6 -6
data/README.md
CHANGED
@@ -1,27 +1,25 @@
|
|
1
|
-
Mongoid::Paperclip - Making Paperclip play nice with Mongoid
|
1
|
+
Mongoid::Paperclip - Making Paperclip play nice with Mongoid ODM
|
2
2
|
================================================================
|
3
3
|
|
4
|
-
As the title suggests
|
5
|
-
|
6
|
-
This is actually **easier** and **faster** to set up than when using the ActiveRecord ORM.
|
4
|
+
As the title suggests: `Mongoid::Paperclip` makes it easy to hook up [Paperclip](https://github.com/thoughtbot/paperclip) with [Mongoid](http://mongoid.org/).
|
7
5
|
|
6
|
+
This is actually easier and faster to set up than when using Paperclip the ActiveRecord ORM.
|
8
7
|
This example assumes you are using **Ruby on Rails 3** and **Bundler**. However it doesn't require either.
|
9
8
|
|
10
9
|
|
11
|
-
Setting it up
|
12
|
-
|
10
|
+
Setting it up
|
11
|
+
-------------
|
13
12
|
|
14
|
-
|
13
|
+
Simply define the `mongoid-paperclip` gem inside your `Gemfile`. Additionally, you can define the `aws-s3` gem if you want to upload your files to Amazon S3. *You do not need to explicitly define the `paperclip` gem itself, since this is handled by `mongoid-paperclip`.*
|
15
14
|
|
16
|
-
**Rails.root/Gemfile
|
15
|
+
**Rails.root/Gemfile - Just define the following:**
|
17
16
|
|
18
|
-
gem "paperclip"
|
19
17
|
gem "mongoid-paperclip", :require => "mongoid_paperclip"
|
20
|
-
gem "aws-s3",
|
18
|
+
gem "aws-s3", :require => "aws/s3"
|
21
19
|
|
22
20
|
Next let's assume we have a User model and we want to allow our users to upload an avatar.
|
23
21
|
|
24
|
-
**Rails.root/app/models/user.rb**
|
22
|
+
**Rails.root/app/models/user.rb - include the Mongoid::Paperclip and invoke the class method**
|
25
23
|
|
26
24
|
class User
|
27
25
|
include Mongoid::Document
|
@@ -31,16 +29,16 @@ Next let's assume we have a User model and we want to allow our users to upload
|
|
31
29
|
end
|
32
30
|
|
33
31
|
|
34
|
-
|
35
|
-
|
32
|
+
That's it
|
33
|
+
--------
|
36
34
|
|
37
|
-
|
35
|
+
That's all you have to do. Users can now upload avatars. Unlike ActiveRecord, Mongoid doesn't use migrations, so we don't need to define the Paperclip columns in a separate file. Invoking the `has_attached_file` method will automatically define the necessary `:avatar` fields for you in the background.
|
38
36
|
|
39
37
|
|
40
38
|
A more complex example
|
41
39
|
----------------------
|
42
40
|
|
43
|
-
Just like
|
41
|
+
Just like Paperclip, Mongoid::Paperclip takes a second argument (hash of options) for the `has_attached_file` method, so you can do more complex things such as in the following example.
|
44
42
|
|
45
43
|
class User
|
46
44
|
include Mongoid::Document
|
@@ -67,7 +65,15 @@ Just like vanilla Paperclip, Mongoid::Paperclip takes a second argument (hash of
|
|
67
65
|
},
|
68
66
|
:convert_options => { :all => '-background white -flatten +matte' }
|
69
67
|
end
|
68
|
+
|
69
|
+
@user.pictures.each do |picture|
|
70
|
+
<%= picture.attachment.url %>
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
There you go
|
75
|
+
------------
|
70
76
|
|
71
|
-
Quite a lot of people have been looking for a solution to use
|
77
|
+
Quite a lot of people have been looking for a solution to use Paperclip with Mongoid so I hope this helps!
|
72
78
|
|
73
|
-
|
79
|
+
If you need more information on either [Mongoid](http://mongoid.org/) or [Paperclip](https://github.com/thoughtbot/paperclip) I suggest checking our their official documentation and website.
|
data/lib/mongoid_paperclip.rb
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
begin
|
2
|
+
require "paperclip"
|
3
|
+
rescue LoadError
|
4
|
+
puts "Mongoid::Paperclip requires that you install the Paperclip gem."
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
1
8
|
##
|
2
9
|
# The logger is set to the Active Record logger by Paperclip itself.
|
3
10
|
# Because of this, we set the logger to false as "default" so that it doesn't raise
|
@@ -24,7 +31,7 @@ end
|
|
24
31
|
|
25
32
|
##
|
26
33
|
# The Mongoid::Paperclip extension
|
27
|
-
# Makes Paperclip play nice with the Mongoid
|
34
|
+
# Makes Paperclip play nice with the Mongoid ODM
|
28
35
|
#
|
29
36
|
# Example:
|
30
37
|
#
|
@@ -3,13 +3,13 @@
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
|
5
5
|
gem.name = 'mongoid-paperclip'
|
6
|
-
gem.version = '0.0.
|
6
|
+
gem.version = '0.0.2'
|
7
7
|
gem.platform = Gem::Platform::RUBY
|
8
8
|
gem.authors = 'Michael van Rooijen'
|
9
9
|
gem.email = 'meskyanichi@gmail.com'
|
10
10
|
gem.homepage = 'https://github.com/meskyanichi/mongoid-paperclip'
|
11
|
-
gem.summary = 'Mongoid::Paperclip enables you to use Paperclip with the Mongoid
|
12
|
-
gem.description = 'Mongoid::Paperclip enables you to use Paperclip with the Mongoid
|
11
|
+
gem.summary = 'Mongoid::Paperclip enables you to use Paperclip with the Mongoid ODM for MongoDB.'
|
12
|
+
gem.description = 'Mongoid::Paperclip enables you to use Paperclip with the Mongoid ODM for MongoDB.'
|
13
13
|
|
14
14
|
gem.files = %x[git ls-files].split("\n")
|
15
15
|
gem.test_files = %x[git ls-files -- {spec}/*].split("\n")
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael van Rooijen
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-11 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 2.3.6
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
|
-
description: Mongoid::Paperclip enables you to use Paperclip with the Mongoid
|
35
|
+
description: Mongoid::Paperclip enables you to use Paperclip with the Mongoid ODM for MongoDB.
|
36
36
|
email: meskyanichi@gmail.com
|
37
37
|
executables: []
|
38
38
|
|
@@ -44,7 +44,7 @@ files:
|
|
44
44
|
- .gitignore
|
45
45
|
- README.md
|
46
46
|
- lib/mongoid_paperclip.rb
|
47
|
-
-
|
47
|
+
- mongoid-paperclip.gemspec
|
48
48
|
has_rdoc: true
|
49
49
|
homepage: https://github.com/meskyanichi/mongoid-paperclip
|
50
50
|
licenses: []
|
@@ -76,6 +76,6 @@ rubyforge_project:
|
|
76
76
|
rubygems_version: 1.3.7
|
77
77
|
signing_key:
|
78
78
|
specification_version: 3
|
79
|
-
summary: Mongoid::Paperclip enables you to use Paperclip with the Mongoid
|
79
|
+
summary: Mongoid::Paperclip enables you to use Paperclip with the Mongoid ODM for MongoDB.
|
80
80
|
test_files: []
|
81
81
|
|