ouvrages_file_uploader 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 208160971d780fa4cb56053aeac7a8d8738a50a0
|
4
|
+
data.tar.gz: 1928964d850c7b7ed7cade7410527e7346709208
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f14f327609e6ac49bbb01d2c80895c623c7e4676d3a8e77a5073485dae26e027e8d8bb95545ded55f1cb876c39d702b7c9bcab18a3c1573ccdf22320fd0732a0
|
7
|
+
data.tar.gz: 34bc58f824bd7c5946f3856af494122e4a6006020f61c91025a27a0d8fba8c81e23734b4851f850a7efff3e683b6c7f3973ad745b43d02ae40e69be5493c7bce
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# OuvragesFileUploader
|
2
|
+
|
3
|
+
Rails Engine to use jQuery File Upload with Paperclip
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ouvrages_file_uploader'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
|
16
|
+
```
|
17
|
+
$ bundle
|
18
|
+
```
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
```
|
23
|
+
$ gem install ouvrages_file_uploader
|
24
|
+
```
|
25
|
+
|
26
|
+
You must already have jquery installed.
|
27
|
+
|
28
|
+
Then add this to your application.js:
|
29
|
+
|
30
|
+
```javascript
|
31
|
+
//= require uploaded_files
|
32
|
+
```
|
33
|
+
|
34
|
+
And this to your application.css:
|
35
|
+
|
36
|
+
```css
|
37
|
+
*= require uploaded_files
|
38
|
+
```
|
39
|
+
|
40
|
+
You need to copy migrations to your project:
|
41
|
+
|
42
|
+
```
|
43
|
+
$ rake ouvrages_file_uploader_engine:install:migrations
|
44
|
+
```
|
45
|
+
|
46
|
+
And then run:
|
47
|
+
|
48
|
+
```
|
49
|
+
$ rake db:migrate
|
50
|
+
```
|
51
|
+
|
52
|
+
## Usage
|
53
|
+
|
54
|
+
Let's consider, we have a resource Post.
|
55
|
+
|
56
|
+
You need to generate a migration for add an attachment:
|
57
|
+
|
58
|
+
```
|
59
|
+
$ rails generate migration add_image_to_posts image:attachment
|
60
|
+
$ rake db:migrate
|
61
|
+
```
|
62
|
+
|
63
|
+
And call in your model `accepts_uploaded_file_for(attribute)`:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
class Post < ActiveRecord::Base
|
67
|
+
attr_accessible :image
|
68
|
+
has_attached_file :image
|
69
|
+
do_not_validate_attachment_file_type :image
|
70
|
+
|
71
|
+
accepts_uploaded_file_for :image
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
Then in your view `app/views/posts/_form.html.erb`:
|
76
|
+
|
77
|
+
```erb
|
78
|
+
<%= file_upload(form, :image) %>
|
79
|
+
```
|
80
|
+
|
81
|
+
For extra information on how to deal with Paperclip, please refer [offical documentation](https://github.com/thoughtbot/paperclip).
|
82
|
+
|
83
|
+
## Contributing
|
84
|
+
|
85
|
+
1. Fork it
|
86
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
87
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
88
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
89
|
+
5. Create new Pull Request
|
@@ -18,8 +18,12 @@ $.fn.ouvragesFileUpload = ->
|
|
18
18
|
filesContainer.append("<div class='progress'><div class='ofu-progress-bar bar' style='width: 0;'></div></div>")
|
19
19
|
return
|
20
20
|
).bind('fileuploaddone', (e, data) ->
|
21
|
-
|
22
|
-
|
21
|
+
if data.result.error or !data.result.files or data.result.files.length == 0
|
22
|
+
$(this).closest('.ofu-field').find('.ofu-progress-bar').text("Error").closest(".progress").addClass("progress-danger")
|
23
|
+
alert(data.result.error.message) if data.result.error.message
|
24
|
+
else
|
25
|
+
$(this).closest('.ofu-field').find('input[type=hidden]').val(data.result.files[0].id)
|
26
|
+
$(this).closest('.ofu-field').find('.ofu-progress-bar').text($(this).closest('.ofu-field').data('text'))
|
23
27
|
|
24
28
|
window.ofuFileCount--
|
25
29
|
return
|
@@ -1,5 +1,12 @@
|
|
1
1
|
class UploadedFilesController < ApplicationController
|
2
2
|
def file_upload
|
3
|
+
# FIX IE
|
4
|
+
if request.headers["HTTP_ACCEPT"].split(",").map(&:strip).include?("application/json")
|
5
|
+
content_type = "application/json"
|
6
|
+
else
|
7
|
+
content_type = "text/plain"
|
8
|
+
end
|
9
|
+
|
3
10
|
uploaded_file = UploadedFile.new(file: params[:files][0])
|
4
11
|
if uploaded_file.save
|
5
12
|
render json: {
|
@@ -11,13 +18,13 @@ class UploadedFilesController < ApplicationController
|
|
11
18
|
"id" => uploaded_file.id
|
12
19
|
}
|
13
20
|
]
|
14
|
-
}
|
21
|
+
}, content_type: content_type
|
15
22
|
else
|
16
23
|
render json: {
|
17
24
|
error: {
|
18
25
|
"message" => "An error prevents the uploaded file to be saved"
|
19
26
|
}
|
20
|
-
}
|
27
|
+
}, content_type: content_type
|
21
28
|
end
|
22
29
|
end
|
23
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ouvrages_file_uploader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ouvrages
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -102,7 +102,7 @@ extensions: []
|
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
104
|
- MIT-LICENSE
|
105
|
-
- README.
|
105
|
+
- README.md
|
106
106
|
- Rakefile
|
107
107
|
- app/assets/javascripts/uploaded_files.js.coffee
|
108
108
|
- app/assets/stylesheets/uploaded_files.css
|
@@ -265,7 +265,6 @@ files:
|
|
265
265
|
- test/dummy/tmp/data/meta_request/843cd09295b195ec53babfb7b625bd60.json
|
266
266
|
- test/dummy/tmp/data/meta_request/bb074b2848c73aa8df59be32febcc413.json
|
267
267
|
- test/dummy/tmp/data/meta_request/d93859d3c64bf924e69a353f1ab74ec1.json
|
268
|
-
- test/dummy/tmp/pids/server.pid
|
269
268
|
- test/fixtures/uploaded_files.yml
|
270
269
|
- test/helpers/uploaded_files_helper_test.rb
|
271
270
|
- test/integration/navigation_test.rb
|
@@ -291,7 +290,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
291
290
|
version: '0'
|
292
291
|
requirements: []
|
293
292
|
rubyforge_project:
|
294
|
-
rubygems_version: 2.
|
293
|
+
rubygems_version: 2.4.5.1
|
295
294
|
signing_key:
|
296
295
|
specification_version: 4
|
297
296
|
summary: Ouvrages File Uploader
|
@@ -330,7 +329,6 @@ test_files:
|
|
330
329
|
- test/dummy/README.rdoc
|
331
330
|
- test/dummy/log/development.log
|
332
331
|
- test/dummy/script/rails
|
333
|
-
- test/dummy/tmp/pids/server.pid
|
334
332
|
- test/dummy/tmp/data/meta_request/bb074b2848c73aa8df59be32febcc413.json
|
335
333
|
- test/dummy/tmp/data/meta_request/56e93e20dbb183c226e62e8fb665b8ab.json
|
336
334
|
- test/dummy/tmp/data/meta_request/15bc2818962b844384424d481eec9517.json
|
@@ -449,4 +447,3 @@ test_files:
|
|
449
447
|
- test/dummy/config.ru
|
450
448
|
- test/helpers/uploaded_files_helper_test.rb
|
451
449
|
- test/controllers/uploaded_files_controller_test.rb
|
452
|
-
has_rdoc:
|
data/README.rdoc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
4104
|