ruby -- 进阶学习(五)使用Ckeditor插件上传中文图片

基于rails4.0环境

当使用Ckeditor上传中文命名图片时报错,解决方法是对图片进行重命名

在Ckeditor插件的安装目录下找到controllers/.../application.rb

比如:E:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\ckeditor-4.0.4\app\controllers\ckeditor\application.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

 

posted @ 2013-08-10 00:28  lmei  阅读(840)  评论(0编辑  收藏  举报