rails_kindeditor 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/kindeditor/assets_controller.rb +5 -15
- data/app/uploaders/kindeditor/asset_uploader.rb +18 -0
- data/app/uploaders/kindeditor/file_uploader.rb +0 -4
- data/app/uploaders/kindeditor/flash_uploader.rb +0 -4
- data/app/uploaders/kindeditor/image_uploader.rb +0 -4
- data/app/uploaders/kindeditor/media_uploader.rb +0 -4
- data/lib/rails_kindeditor/version.rb +1 -1
- metadata +4 -4
@@ -6,7 +6,7 @@ class Kindeditor::AssetsController < ApplicationController
|
|
6
6
|
@imgFile = params[:imgFile]
|
7
7
|
@dir = params[:dir]
|
8
8
|
unless @imgFile.nil?
|
9
|
-
if save_upload_info? # save upload info into database
|
9
|
+
if Kindeditor::AssetUploader.save_upload_info? # save upload info into database
|
10
10
|
begin
|
11
11
|
@asset = "Kindeditor::#{@dir.camelize}".constantize.new(:asset => @imgFile)
|
12
12
|
if @asset.save
|
@@ -14,8 +14,8 @@ class Kindeditor::AssetsController < ApplicationController
|
|
14
14
|
else
|
15
15
|
show_error(@asset.errors.full_messages)
|
16
16
|
end
|
17
|
-
rescue
|
18
|
-
show_error(
|
17
|
+
rescue Exception => e
|
18
|
+
show_error(e.to_s)
|
19
19
|
end
|
20
20
|
else # do not touch database
|
21
21
|
begin
|
@@ -24,8 +24,8 @@ class Kindeditor::AssetsController < ApplicationController
|
|
24
24
|
render :text => ({:error => 0, :url => uploader.url}.to_json)
|
25
25
|
rescue CarrierWave::UploadError => e
|
26
26
|
show_error(e.message)
|
27
|
-
rescue
|
28
|
-
show_error(
|
27
|
+
rescue Exception => e
|
28
|
+
show_error(e.to_s)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
else
|
@@ -115,14 +115,4 @@ class Kindeditor::AssetsController < ApplicationController
|
|
115
115
|
render :text => ({:error => 1, :message => msg}.to_json)
|
116
116
|
end
|
117
117
|
|
118
|
-
def save_upload_info?
|
119
|
-
begin
|
120
|
-
%w(asset file flash image media).each do |s|
|
121
|
-
"Kindeditor::#{s.camelize}".constantize
|
122
|
-
end
|
123
|
-
return true
|
124
|
-
rescue
|
125
|
-
return false
|
126
|
-
end
|
127
|
-
end
|
128
118
|
end
|
@@ -17,6 +17,13 @@ class Kindeditor::AssetUploader < CarrierWave::Uploader::Base
|
|
17
17
|
|
18
18
|
# Override the directory where uploaded files will be stored.
|
19
19
|
# This is a sensible default for uploaders that are meant to be mounted:
|
20
|
+
def store_dir
|
21
|
+
if Kindeditor::AssetUploader.save_upload_info?
|
22
|
+
"uploads/#{model.class.to_s.underscore}/#{model.created_at.strftime("%Y%m")}"
|
23
|
+
else
|
24
|
+
"uploads/#{self.class.to_s.underscore.gsub(/(kindeditor\/)|(_uploader)/, '')}/#{Time.now.strftime("%Y%m")}"
|
25
|
+
end
|
26
|
+
end
|
20
27
|
|
21
28
|
def cache_dir
|
22
29
|
"#{Rails.root}/tmp/uploads"
|
@@ -63,6 +70,17 @@ class Kindeditor::AssetUploader < CarrierWave::Uploader::Base
|
|
63
70
|
@name ||= Time.now.to_s(:number)
|
64
71
|
"#{@name}#{File.extname(original_filename).downcase}" if original_filename
|
65
72
|
end
|
73
|
+
|
74
|
+
def self.save_upload_info?
|
75
|
+
begin
|
76
|
+
%w(asset file flash image media).each do |s|
|
77
|
+
"Kindeditor::#{s.camelize}".constantize
|
78
|
+
end
|
79
|
+
return true
|
80
|
+
rescue
|
81
|
+
return false
|
82
|
+
end
|
83
|
+
end
|
66
84
|
|
67
85
|
end
|
68
86
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_kindeditor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Macrow
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-04 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: carrierwave
|