uploadcare-rails 0.5 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -2
- data/lib/uploadcare/rails/file.rb +3 -0
- data/lib/uploadcare/rails/version.rb +1 -1
- metadata +6 -6
data/README.md
CHANGED
@@ -11,7 +11,9 @@ This is a Rails gem for using the [Uploadcare.com](https://uploadcare.com) servi
|
|
11
11
|
|
12
12
|
# Usage
|
13
13
|
|
14
|
-
This gem provides ability to attach Uploadcare files to your models. To do that, you need a string field in your model, which is going to hold an Uploadcare file's
|
14
|
+
This gem provides ability to attach Uploadcare files to your models. To do that, you need a string field in your model, which is going to hold an Uploadcare file's CDN URL.
|
15
|
+
|
16
|
+
## Configuration
|
15
17
|
|
16
18
|
The first thing is to configure stuff for Uploadcare. Create a file `config/initializers/uploadcare.rb`:
|
17
19
|
|
@@ -25,7 +27,9 @@ end
|
|
25
27
|
|
26
28
|
(These are our *demo* keys. You can use them to try things out. Don't forget to change them to your own keys before building anything serious).
|
27
29
|
|
28
|
-
|
30
|
+
## Models
|
31
|
+
|
32
|
+
Add an attribute to your model. First, create and run a migration:
|
29
33
|
|
30
34
|
rails generate migration AddFileToPost file:string
|
31
35
|
rake db:migrate
|
@@ -39,6 +43,8 @@ class Post < ActiveRecord::Base
|
|
39
43
|
end
|
40
44
|
```
|
41
45
|
|
46
|
+
## Forms
|
47
|
+
|
42
48
|
To display nice widgets for file upload, include the script for desired widget version (here we use 0.8) in your layout.
|
43
49
|
|
44
50
|
```erb
|
@@ -64,12 +70,21 @@ Now we can use the Uploadcare widget in our forms:
|
|
64
70
|
<%= form.input :file, as: :uploadcare_uploader %>
|
65
71
|
```
|
66
72
|
|
73
|
+
## Displaying files
|
74
|
+
|
67
75
|
Uploadcare-rails gem takes care of storing files when saving a model, so as soon as you add a field to your form, everything should work, and you'll be able to show an image just like that:
|
68
76
|
|
69
77
|
```erb
|
70
78
|
<%= image_tag @post.file.public_url("scale_crop/500x200", "effect/grayscale/") %>
|
71
79
|
```
|
72
80
|
|
81
|
+
If you need the unique identifier that Uploadcare uses to represent a file,
|
82
|
+
it is available like so:
|
83
|
+
|
84
|
+
```erb
|
85
|
+
UUID: <%= @post.file.uuid %>
|
86
|
+
```
|
87
|
+
|
73
88
|
[Other information](https://uploadcare.com/documentation/rest/#file) about the file is accessed through the `api` method that makes a single HTTP request to Uploadcare servers **for each file**. Use cautiously or cache the returned information somewhere.
|
74
89
|
|
75
90
|
```erb
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uploadcare-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - '='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.1.
|
37
|
+
version: 0.1.3
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - '='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.1.
|
45
|
+
version: 0.1.3
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: sqlite3
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
segments:
|
127
127
|
- 0
|
128
|
-
hash:
|
128
|
+
hash: 589296094626255703
|
129
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
130
|
none: false
|
131
131
|
requirements:
|
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
version: '0'
|
135
135
|
segments:
|
136
136
|
- 0
|
137
|
-
hash:
|
137
|
+
hash: 589296094626255703
|
138
138
|
requirements: []
|
139
139
|
rubyforge_project:
|
140
140
|
rubygems_version: 1.8.24
|