基于rails4.0环境
当使用Ckeditor上传中文命名图片时报错,解决方法是对图片进行重命名
在Ckeditor插件的安装目录下找到controllers/.../application.rb
比如:E:RailsInstallerRuby1.9.3lib ubygems1.9.1gemsckeditor-4.0.4appcontrollersckeditorapplication.rb
然后找到 def respond_with_asset(asset)
1 def respond_with_asset(asset) 2 file = params[:CKEditor].blank? ? params[:qqfile] : params[:upload] 3 asset.data = Ckeditor::Http.normalize_param(file, request) 4 …… 5 end
修改如下:
1 def respond_with_asset(asset) 2 file = params[:CKEditor].blank? ? params[:qqfile] : params[:upload] 3 extension = File.extname( file.original_filename.to_s).downcase 4 file.original_filename .replace(Time.now.strftime("%Y%m%d%H%M%S")+rand(10000).to_s+extension) 5 asset.data = Ckeditor::Http.normalize_param(file, request) 6 …… 7 end