carrierwave-mongoid 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +27 -22
- data/lib/carrierwave/mongoid.rb +2 -1
- data/lib/carrierwave/mongoid/version.rb +1 -1
- data/spec/mongoid_spec.rb +8 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -1,33 +1,20 @@
|
|
1
1
|
# CarrierWave for Mongoid
|
2
2
|
|
3
|
-
This gem adds support for Mongoid and MongoDB's GridFS to CarrierWave
|
4
|
-
CarrierWave documentation for more detailed usage instructions.
|
3
|
+
This gem adds support for Mongoid and MongoDB's GridFS to [CarrierWave](https://github.com/jnicklas/carrierwave/)
|
5
4
|
|
6
|
-
|
7
|
-
Keep in mind that if you came up from previous versions you should make a few steps to go with it:
|
5
|
+
This functionality used to be part of CarrierWave but has since been extracted into this gem.
|
8
6
|
|
9
|
-
|
10
|
-
* fix you code where you need to operate with uploaded file's filename from `avatar` to `avatar_identifier`
|
11
|
-
|
12
|
-
Install it like this:
|
7
|
+
## Installation
|
13
8
|
|
14
9
|
gem install carrierwave-mongoid
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
```ruby
|
19
|
-
require 'carrierwave/mongoid'
|
20
|
-
```
|
21
|
-
|
22
|
-
Make sure to disable auto_validation on the mounted column.
|
11
|
+
## Requiring the gem
|
23
12
|
|
24
|
-
|
13
|
+
require 'carrierwave/mongoid'
|
25
14
|
|
26
|
-
|
27
|
-
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
|
28
|
-
```
|
15
|
+
## Using Bundler
|
29
16
|
|
30
|
-
|
17
|
+
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
|
31
18
|
|
32
19
|
## Using MongoDB's GridFS store
|
33
20
|
|
@@ -61,8 +48,26 @@ CarrierWave.configure do |config|
|
|
61
48
|
end
|
62
49
|
```
|
63
50
|
|
64
|
-
##
|
51
|
+
## Changes from earlier versions of CarrierWave with Mongoid support built in
|
52
|
+
|
53
|
+
This version supports ONLY version of mongoid ~> 2.1
|
54
|
+
|
55
|
+
You can use `upload_identifier` to retrieve the original name of the uploaded file.
|
56
|
+
|
57
|
+
The default mount column used to be the name of the upload column plus `_filename`. Now it is simply the name of the column. Most of the time, the column was called `upload`, so it would have been mounted to `upload_filename`.
|
58
|
+
If you'd like to avoid a database migration, simply use the `:mount_on` option to specify
|
59
|
+
the field name explicitly. Therefore, you only have to add a `_filename` to your column name. For example, if your column is called `:upload`:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
class Dokument
|
63
|
+
mount_uploader :upload, DokumentUploader, mount_on: :upload_filename
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
## Known issues and limitations
|
68
|
+
|
69
|
+
It is recommended that you disable Mongoid's auto_validation on the mounted column.
|
65
70
|
|
66
|
-
|
71
|
+
Note that embedded documents files aren't saved when parent documents are saved.
|
67
72
|
You must explicitly call save on embedded documents in order to save their attached files.
|
68
73
|
You can read more about this [here](https://github.com/jnicklas/carrierwave/issues#issue/81)
|
data/lib/carrierwave/mongoid.rb
CHANGED
@@ -41,7 +41,8 @@ module CarrierWave
|
|
41
41
|
def find_previous_model_for_#{column}
|
42
42
|
if self.embedded?
|
43
43
|
ancestors = [[ self.metadata.key, self._parent ]].tap { |x| x.unshift([ x.first.last.metadata.key, x.first.last._parent ]) while x.first.last.embedded? }
|
44
|
-
|
44
|
+
first_parent = ancestors.first.last
|
45
|
+
reloaded_parent = first_parent.class.find(first_parent.to_key.first)
|
45
46
|
ancestors.inject(reloaded_parent) { |parent,(key,ancestor)| (parent.is_a?(Array) ? parent.find(ancestor.to_key.first) : parent).send(key) }.find(to_key.first)
|
46
47
|
else
|
47
48
|
self.class.find(to_key.first)
|
data/spec/mongoid_spec.rb
CHANGED
@@ -450,6 +450,14 @@ describe CarrierWave::Mongoid do
|
|
450
450
|
File.exists?(public_path('uploads/old.jpeg')).should be_true
|
451
451
|
end
|
452
452
|
|
453
|
+
it "should not touch parent's dirty attributes" do
|
454
|
+
@class.field :title
|
455
|
+
@doc.title = "Title"
|
456
|
+
@embedded_doc.image = stub_file('new.jpeg')
|
457
|
+
@embedded_doc.save.should be_true
|
458
|
+
@doc.title.should == "Title"
|
459
|
+
end
|
460
|
+
|
453
461
|
describe 'with double embedded documents' do
|
454
462
|
|
455
463
|
before do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jonas Nicklas
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-08-
|
19
|
+
date: 2011-08-16 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|