rails-uploader 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -10
- data/lib/uploader/asset.rb +0 -6
- data/lib/uploader/version.rb +1 -1
- data/spec/dummy/app/models/asset.rb +2 -0
- data/spec/dummy/log/test.log +81 -0
- data/spec/dummy/public/uploads/picture/data/1/thumb_rails.png +0 -0
- data/spec/dummy/public/uploads/picture/data/3/thumb_rails.png +0 -0
- data/spec/mongoid_spec.rb +2 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -63,12 +63,13 @@ class Picture < Asset
|
|
63
63
|
validates_filesize_of :data, :maximum => 2.megabytes.to_i
|
64
64
|
|
65
65
|
# structure of returned json array of files. (used in Hash.to_json operation)
|
66
|
-
def serializable_hash
|
66
|
+
def serializable_hash(options=nil)
|
67
67
|
{
|
68
|
-
|
68
|
+
"id" => id.to_s,
|
69
69
|
"filename" => File.basename(data.path),
|
70
70
|
"url" => data.url,
|
71
|
-
|
71
|
+
"thumb_url" => data.url(:thumb),
|
72
|
+
"public_token" => public_token
|
72
73
|
}
|
73
74
|
end
|
74
75
|
end
|
@@ -129,43 +130,44 @@ class User
|
|
129
130
|
|
130
131
|
fileuploads :picture, :avatar
|
131
132
|
end
|
133
|
+
```
|
132
134
|
|
133
135
|
|
134
136
|
### Include assets
|
135
137
|
|
136
138
|
Javascripts:
|
137
139
|
|
138
|
-
```
|
140
|
+
```
|
139
141
|
//= require uploader/application
|
140
142
|
```
|
141
143
|
|
142
144
|
Stylesheets:
|
143
145
|
|
144
|
-
```
|
146
|
+
```
|
145
147
|
*= require uploader/application
|
146
148
|
```
|
147
149
|
|
148
150
|
### Views
|
149
151
|
|
150
|
-
```
|
152
|
+
```erb
|
151
153
|
<%= uploader_field_tag :article, :photo %>
|
152
154
|
```
|
153
155
|
|
154
156
|
or FormBuilder:
|
155
157
|
|
156
|
-
```
|
158
|
+
```erb
|
157
159
|
<%= form.uploader_field :photo, :sortable => true %>
|
158
160
|
```
|
159
161
|
|
160
162
|
### Formtastic
|
161
163
|
|
162
|
-
```
|
164
|
+
```erb
|
163
165
|
<%= f.input :pictures, :as => :uploader %>
|
164
166
|
```
|
165
167
|
|
166
168
|
### SimpleForm
|
167
169
|
|
168
|
-
```
|
170
|
+
```erb
|
169
171
|
<%= f.input :pictures, :as => :uploader, :input_html => {:sortable => true} %>
|
170
172
|
```
|
171
173
|
|
@@ -173,7 +175,7 @@ or FormBuilder:
|
|
173
175
|
|
174
176
|
This is only working in Formtastic and FormBuilder:
|
175
177
|
|
176
|
-
```
|
178
|
+
``` erb
|
177
179
|
# formtastic
|
178
180
|
<%= f.input :picture, :as => :uploader, :confirm_delete => true %>
|
179
181
|
# the i18n lookup key would be en.formtastic.delete_confirmations.picture
|
data/lib/uploader/asset.rb
CHANGED
@@ -3,10 +3,6 @@ module Uploader
|
|
3
3
|
def self.included(base)
|
4
4
|
base.send(:extend, Uploader::Asset::ClassMethods)
|
5
5
|
base.send(:include, Uploader::Asset::AssetProcessor)
|
6
|
-
|
7
|
-
base.instance_eval do
|
8
|
-
before_create :generate_public_token
|
9
|
-
end
|
10
6
|
end
|
11
7
|
|
12
8
|
module Mongoid
|
@@ -17,8 +13,6 @@ module Uploader
|
|
17
13
|
base.instance_eval do
|
18
14
|
field :guid, type: String
|
19
15
|
field :public_token, type: String
|
20
|
-
|
21
|
-
before_create :generate_public_token
|
22
16
|
end
|
23
17
|
end
|
24
18
|
|
data/lib/uploader/version.rb
CHANGED
data/spec/dummy/log/test.log
CHANGED
@@ -2246,3 +2246,84 @@ Started POST "/uploader/attachments" for 127.0.0.1 at 2013-09-05 18:45:19 +0300
|
|
2246
2246
|
[1m[35m (0.1ms)[0m begin transaction
|
2247
2247
|
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
2248
2248
|
MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=system.namespaces selector={:name=>{"$not"=>/system|\$/}} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.4129ms)
|
2249
|
+
Connecting to database specified by database.yml
|
2250
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
2251
|
+
Migrating to CreateAssets (20120508093416)
|
2252
|
+
Migrating to CreateArticles (20120508093830)
|
2253
|
+
[1m[35m (0.1ms)[0m begin transaction
|
2254
|
+
[1m[36m (0.1ms)[0m [1mSAVEPOINT active_record_1[0m
|
2255
|
+
[1m[35mSQL (4.3ms)[0m INSERT INTO "articles" ("content", "created_at", "title", "updated_at") VALUES (?, ?, ?, ?) [["content", "MyText"], ["created_at", Sat, 07 Sep 2013 06:36:54 UTC +00:00], ["title", "MyString"], ["updated_at", Sat, 07 Sep 2013 06:36:54 UTC +00:00]]
|
2256
|
+
[1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
2257
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
2258
|
+
[1m[36mPicture Exists (0.1ms)[0m [1mSELECT 1 AS one FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."public_token" = 'AWt2HVkcENAITwiipl91' LIMIT 1[0m
|
2259
|
+
[1m[35mSQL (0.7ms)[0m INSERT INTO "assets" ("assetable_id", "assetable_type", "created_at", "data_content_type", "data_file_name", "data_file_size", "guid", "public_token", "type", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["assetable_id", 1], ["assetable_type", "Article"], ["created_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["data_content_type", "image/png"], ["data_file_name", "rails.png"], ["data_file_size", nil], ["guid", nil], ["public_token", "AWt2HVkcENAITwiipl91"], ["type", "Picture"], ["updated_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["user_id", nil]]
|
2260
|
+
[1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
2261
|
+
[1m[35mPicture Load (0.3ms)[0m SELECT "assets".* FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."guid" IS NULL AND "assets"."assetable_type" = 'Article' LIMIT 1
|
2262
|
+
[1m[36mSQL (0.2ms)[0m [1mUPDATE "assets" SET "assetable_id" = 1000, "guid" = NULL WHERE "assets"."type" IN ('Picture') AND "assets"."guid" IS NULL AND "assets"."assetable_type" = 'Article'[0m
|
2263
|
+
[1m[35mPicture Load (0.1ms)[0m SELECT "assets".* FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."id" = ? LIMIT 1 [["id", 1]]
|
2264
|
+
[1m[36mPicture Load (0.2ms)[0m [1mSELECT "assets".* FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."guid" = 'tERRDemHo1OMihKx3oBP' AND "assets"."assetable_type" = 'Article' LIMIT 1[0m
|
2265
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
2266
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
2267
|
+
[1m[35m (2.4ms)[0m rollback transaction
|
2268
|
+
MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} (21.0221ms)
|
2269
|
+
MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=system.namespaces selector={:name=>{"$not"=>/system|\$/}} flags=[:slave_ok] limit=0 skip=0 fields=nil (7.5850ms)
|
2270
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2271
|
+
MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=mongoid_pictures selector={"public_token"=>"gRMFvS8x2Rr0ec3iEXP8"} flags=[:slave_ok] limit=1 skip=0 fields={:_id=>1} (10.9842ms)
|
2272
|
+
MOPED: 127.0.0.1:27017 INSERT database=rails_uploader_test collection=mongoid_pictures documents=[{"_id"=>"522ac987dc26e7e3c4000001", "guid"=>"guid", "assetable_type"=>"MongoidArticle", "public_token"=>"gRMFvS8x2Rr0ec3iEXP8"}] flags=[] (0.1829ms)
|
2273
|
+
MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=mongoid_pictures selector={"$query"=>{"guid"=>"guid", "assetable_type"=>"MongoidArticle"}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 fields=nil (28.3999ms)
|
2274
|
+
MOPED: 127.0.0.1:27017 COMMAND database=rails_uploader_test command={:count=>"mongoid_pictures", :query=>{}} (1.3881ms)
|
2275
|
+
MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=mongoid_pictures selector={} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.3190ms)
|
2276
|
+
MOPED: 127.0.0.1:27017 DELETE database=rails_uploader_test collection=mongoid_pictures selector={"_id"=>"522ac987dc26e7e3c4000001"} flags=[:remove_first] (0.1488ms)
|
2277
|
+
MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=mongoid_pictures selector={"public_token"=>"ORqLAVteAhpTVGWHXOjC"} flags=[:slave_ok] limit=1 skip=0 fields={:_id=>1} (0.7150ms)
|
2278
|
+
MOPED: 127.0.0.1:27017 INSERT database=rails_uploader_test collection=mongoid_pictures documents=[{"_id"=>"522ac987dc26e7e3c4000002", "guid"=>"guid", "assetable_type"=>"MongoidArticle", "public_token"=>"ORqLAVteAhpTVGWHXOjC"}] flags=[] (0.1011ms)
|
2279
|
+
MOPED: 127.0.0.1:27017 UPDATE database=rails_uploader_test collection=mongoid_pictures selector={"guid"=>"guid", "assetable_type"=>"MongoidArticle"} update={"$set"=>{:assetable_id=>1000, :guid=>nil}} flags=[:multi] (0.1230ms)
|
2280
|
+
MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=mongoid_pictures selector={:_id=>"522ac987dc26e7e3c4000002"} flags=[:slave_ok] limit=-1 skip=0 fields=nil (3.6292ms)
|
2281
|
+
MOPED: 127.0.0.1:27017 COMMAND database=rails_uploader_test command={:count=>"mongoid_pictures", :query=>{}} (0.4101ms)
|
2282
|
+
MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=mongoid_pictures selector={} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.2871ms)
|
2283
|
+
MOPED: 127.0.0.1:27017 DELETE database=rails_uploader_test collection=mongoid_pictures selector={"_id"=>"522ac987dc26e7e3c4000002"} flags=[:remove_first] (0.0710ms)
|
2284
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2285
|
+
MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=system.namespaces selector={:name=>{"$not"=>/system|\$/}} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.4151ms)
|
2286
|
+
MOPED: 127.0.0.1:27017 COMMAND database=rails_uploader_test command={:drop=>"mongoid_pictures"} (9.9230ms)
|
2287
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2288
|
+
|
2289
|
+
|
2290
|
+
Started POST "/uploader/attachments" for 127.0.0.1 at 2013-09-07 09:36:55 +0300
|
2291
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
2292
|
+
[1m[36mPicture Exists (0.2ms)[0m [1mSELECT 1 AS one FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."public_token" = '7PSgybt0d7BfJOUHdpve' LIMIT 1[0m
|
2293
|
+
[1m[35mSQL (0.6ms)[0m INSERT INTO "assets" ("assetable_id", "assetable_type", "created_at", "data_content_type", "data_file_name", "data_file_size", "guid", "public_token", "type", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["assetable_id", 1], ["assetable_type", "Article"], ["created_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["data_content_type", nil], ["data_file_name", "rails.png"], ["data_file_size", nil], ["guid", "SOMESTRING"], ["public_token", "7PSgybt0d7BfJOUHdpve"], ["type", "Picture"], ["updated_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["user_id", nil]]
|
2294
|
+
[1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
2295
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
2296
|
+
[1m[36mSQL (0.6ms)[0m [1mINSERT INTO "articles" ("content", "created_at", "title", "updated_at") VALUES (?, ?, ?, ?)[0m [["content", "MyText"], ["created_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["title", "MyString"], ["updated_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00]]
|
2297
|
+
[1m[35m (0.0ms)[0m RELEASE SAVEPOINT active_record_1
|
2298
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
2299
|
+
[1m[35mPicture Exists (0.1ms)[0m SELECT 1 AS one FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."public_token" = 'dqTLYqXzmZOVibKNUmBn' LIMIT 1
|
2300
|
+
[1m[36mSQL (0.3ms)[0m [1mINSERT INTO "assets" ("assetable_id", "assetable_type", "created_at", "data_content_type", "data_file_name", "data_file_size", "guid", "public_token", "type", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)[0m [["assetable_id", 1], ["assetable_type", "Article"], ["created_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["data_content_type", "image/png"], ["data_file_name", "rails.png"], ["data_file_size", nil], ["guid", nil], ["public_token", "dqTLYqXzmZOVibKNUmBn"], ["type", "Picture"], ["updated_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["user_id", nil]]
|
2301
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
2302
|
+
[1m[36m (0.3ms)[0m [1mSELECT COUNT(*) FROM "assets" WHERE "assets"."type" IN ('Picture')[0m
|
2303
|
+
|
2304
|
+
|
2305
|
+
Started DELETE "/uploader/attachments/dqTLYqXzmZOVibKNUmBn" for 127.0.0.1 at 2013-09-07 09:36:55 +0300
|
2306
|
+
[1m[35mPicture Load (0.2ms)[0m SELECT "assets".* FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."public_token" = 'dqTLYqXzmZOVibKNUmBn' LIMIT 1
|
2307
|
+
[1m[36m (0.0ms)[0m [1mSAVEPOINT active_record_1[0m
|
2308
|
+
[1m[35mSQL (0.3ms)[0m DELETE FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."id" = ? [["id", 2]]
|
2309
|
+
[1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
2310
|
+
[1m[35m (0.2ms)[0m SELECT COUNT(*) FROM "assets" WHERE "assets"."type" IN ('Picture')
|
2311
|
+
[1m[36m (0.1ms)[0m [1mSAVEPOINT active_record_1[0m
|
2312
|
+
[1m[35mSQL (0.5ms)[0m INSERT INTO "articles" ("content", "created_at", "title", "updated_at") VALUES (?, ?, ?, ?) [["content", "MyText"], ["created_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["title", "MyString"], ["updated_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00]]
|
2313
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
2314
|
+
[1m[35m (0.0ms)[0m SAVEPOINT active_record_1
|
2315
|
+
[1m[36mPicture Exists (0.1ms)[0m [1mSELECT 1 AS one FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."public_token" = 'KHcKVIB0QJ0xDGYrOONx' LIMIT 1[0m
|
2316
|
+
[1m[35mSQL (0.2ms)[0m INSERT INTO "assets" ("assetable_id", "assetable_type", "created_at", "data_content_type", "data_file_name", "data_file_size", "guid", "public_token", "type", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["assetable_id", 2], ["assetable_type", "Article"], ["created_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["data_content_type", "image/png"], ["data_file_name", "rails.png"], ["data_file_size", nil], ["guid", nil], ["public_token", "KHcKVIB0QJ0xDGYrOONx"], ["type", "Picture"], ["updated_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["user_id", nil]]
|
2317
|
+
[1m[36m (0.0ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
2318
|
+
|
2319
|
+
|
2320
|
+
Started DELETE "/uploader/attachments/wrong" for 127.0.0.1 at 2013-09-07 09:36:55 +0300
|
2321
|
+
[1m[35mPicture Load (0.1ms)[0m SELECT "assets".* FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."public_token" = 'wrong' LIMIT 1
|
2322
|
+
|
2323
|
+
|
2324
|
+
Started POST "/uploader/attachments" for 127.0.0.1 at 2013-09-07 09:36:55 +0300
|
2325
|
+
[1m[36m (1.8ms)[0m [1mrollback transaction[0m
|
2326
|
+
MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=system.namespaces selector={:name=>{"$not"=>/system|\$/}} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.5319ms)
|
2327
|
+
[1m[35m (0.1ms)[0m begin transaction
|
2328
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
2329
|
+
MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=system.namespaces selector={:name=>{"$not"=>/system|\$/}} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.4559ms)
|
Binary file
|
Binary file
|
data/spec/mongoid_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-uploader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-09-
|
13
|
+
date: 2013-09-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jquery-ui-rails
|