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.
@@ -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("Internal 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("Internal 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
 
@@ -2,10 +2,6 @@
2
2
 
3
3
  class Kindeditor::FileUploader < Kindeditor::AssetUploader
4
4
 
5
- def store_dir
6
- "uploads/file/#{Time.now.strftime("%Y%m")}"
7
- end
8
-
9
5
  def extension_white_list
10
6
  EXT_NAMES[:file]
11
7
  end
@@ -2,10 +2,6 @@
2
2
 
3
3
  class Kindeditor::FlashUploader < Kindeditor::AssetUploader
4
4
 
5
- def store_dir
6
- "uploads/flash/#{Time.now.strftime("%Y%m")}"
7
- end
8
-
9
5
  def extension_white_list
10
6
  EXT_NAMES[:flash]
11
7
  end
@@ -2,10 +2,6 @@
2
2
 
3
3
  class Kindeditor::ImageUploader < Kindeditor::AssetUploader
4
4
 
5
- def store_dir
6
- "uploads/image/#{Time.now.strftime("%Y%m")}"
7
- end
8
-
9
5
  def extension_white_list
10
6
  EXT_NAMES[:image]
11
7
  end
@@ -2,10 +2,6 @@
2
2
 
3
3
  class Kindeditor::MediaUploader < Kindeditor::AssetUploader
4
4
 
5
- def store_dir
6
- "uploads/media/#{Time.now.strftime("%Y%m")}"
7
- end
8
-
9
5
  def extension_white_list
10
6
  EXT_NAMES[:media]
11
7
  end
@@ -1,4 +1,4 @@
1
1
  module RailsKindeditor
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
4
4
 
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
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-02 00:00:00 Z
18
+ date: 2011-10-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: carrierwave