-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathwysi_html_five_asset.rb
More file actions
75 lines (66 loc) · 1.98 KB
/
wysi_html_five_asset.rb
File metadata and controls
75 lines (66 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
ActiveAdmin.register WysiHtmlFiveAsset do
index as: :grid do |asset|
link_to(image_tag(asset.storage.thumb("100x100#").url), admin_asset_path(asset))
end
form do |f|
f.inputs do
f.input :storage, as: :dragonfly, input_html: { components: [:preview, :upload, :url, :remove ] }
end
f.actions
end
show do
attributes_table do
row('Dimensions') do
"#{asset.storage.width}px x #{asset.storage.height}px"
end
row('Thumbnail') do
image_tag(asset.thumb_url)
end
row('25%') do
image_tag(asset.percentage_thumb_url(0.25))
end
row('50%') do
image_tag(asset.percentage_thumb_url(0.5))
end
row('75%') do
image_tag(asset.percentage_thumb_url(0.75))
end
row('Full Image') do
image_tag(asset.storage.url)
end
end
end
controller do
def permitted_params
params.permit asset: [:storage, :retained_storage, :remove_storage, :storage_url]
end
def create
# If an app is using Rack::RawUpload, it can just use
# params['file'] and not worry with original_filename parsing.
if params['file']
@asset = WysiHtmlFiveAsset.new
@asset.storage = params['file']
if @asset.save!
render json: { success: true }.to_json
else
render nothing: true, status: 500 and return
end
elsif params['qqfile']
@asset = WysiHtmlFiveAsset.new
io = request.env['rack.input']
# throw io
# def io.original_filename=(name) @original_filename = name; end
# def io.original_filename() @original_filename; end
# io.original_filename = params['qqfile']
@asset.storage = Dragonfly::TempObject.new(io.respond_to?(:string) ? io.string : io.read)
if @asset.save!
render json: { success: true }.to_json
else
render nothing: true, status: 500 and return
end
else
create!
end
end
end
end