本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7593530
建立时间:2006年5月29日




[Ruby on Rails]rails实战--(四)FCKEditor与rails的集成
软件技术

lhwork 发表于 2007/1/20 11:02:49

1.下载fckeditor_plugin-0.3.2.zip,目前版本为0.3.22.解压到vendor\plugins目录下,并且重新命名为fckeditor3.到该应用程序根目录下,然后运行rake fckeditor:install,则执行自动安装4.在自己的view层中添加<%= javascript_include_tag :fckeditor %>以及在你需要编辑的字段textarea替换为<%= fckeditor_textarea("book", "desc", { :toolbarKit => 'Simple', :width => '100%', :height => '200px' }) %>第一个参数为你的domain对象,desc为你的编辑字段值,其他顾名思义然后运行你的页面程序,发现simple upload有点bug,上传后javascript报错5.追踪代码发现vendor\plugins\fckeditor\app\controllers\fckeditor_controller.rb下的500)this.width=500'>  def upload500)this.width=500'>    self.upload_file500)this.width=500'>  end调用了upload_file方法500)this.width=500'>def upload_file500)this.width=500'>    @new_file = params[:NewFile]500)this.width=500'>    @url = upload_directory_path500)this.width=500'>    begin500)this.width=500'>      ftype = @new_file.content_type.strip500)this.width=500'>      if ! MIME_TYPES.include?(ftype)500)this.width=500'>        @errorNumber = 202500)this.width=500'>        puts "#{ftype} is invalid MIME type"500)this.width=500'>        raise "#{ftype} is invalid MIME type"500)this.width=500'>      else500)this.width=500'>        path = current_directory_path + "/" + @new_file.original_filename500)this.width=500'>        File.open(path,"wb",0664) do |fp|500)this.width=500'>          FileUtils.copy_stream(@new_file, fp)500)this.width=500'>        end500)this.width=500'>        @errorNumber = 0500)this.width=500'>      end500)this.width=500'>    rescue => e500)this.width=500'>      @errorNumber = 110 if @errorNumber.nil?500)this.width=500'>    end500)this.width=500'>    500)this.width=500'>    # Fix provided by Nicola Piccinini -- http://superfluo.org500)this.width=500'>    render :text => %Q'<script>window.parent.frames[\'frmUpload\'].OnUploadCompleted(#{@errorNumber});</script>'500)this.width=500'>500)this.width=500'>    #render :inline => 'page << "window.parent.frames[\'frmUpload\'].OnUploadCompleted(#{@errorNumber}, \'#500)this.width=500'>{@new_file}\');"', :type => :rjs500)this.width=500'>  end中的500)this.width=500'>render :text => %Q'<script>window.parent.frames[\'frmUpload\'].OnUploadCompleted(#{@errorNumber});</script>'在浏览服务器时是正常的,但是在快速上传中不应该返回这个script语句则修改upload方法500)this.width=500'>def upload500)this.width=500'>    @new_file = params[:NewFile]500)this.width=500'>    @url = upload_directory_path500)this.width=500'>    begin500)this.width=500'>      ftype = @new_file.content_type.strip500)this.width=500'>      if ! MIME_TYPES.include?(ftype)500)this.width=500'>        @errorNumber = 202500)this.width=500'>        puts "#{ftype} is invalid MIME type"500)this.width=500'>        raise "#{ftype} is invalid MIME type"500)this.width=500'>      else500)this.width=500'>        path = current_directory_path + "/" + @new_file.original_filename500)this.width=500'>        File.open(path,"wb",0664) do |fp|500)this.width=500'>          FileUtils.copy_stream(@new_file, fp)500)this.width=500'>        end500)this.width=500'>        @errorNumber = 0500)this.width=500'>      end500)this.width=500'>    rescue => e500)this.width=500'>      @errorNumber = 110 if @errorNumber.nil?500)this.width=500'>    end500)this.width=500'>    500)this.width=500'>    # Fix provided by Nicola Piccinini -- http://superfluo.org500)this.width=500'>    render :text => %Q'<script>window.parent.OnUploadCompleted(#{@errorNumber},\"#{UPLOADED}/#{params[:Type]}\",\"#{@new_file.original_filename}\",\"\");</script>'500)this.width=500'>  end快速上传问题修复6.发现文件夹里边如果上传图片过多不好备份,故采用/年/月方式保存修改代码如下:500)this.width=500'>   def upload500)this.width=500'>    @new_file = params[:NewFile]500)this.width=500'>    @url = upload_directory_path500)this.width=500'>    begin500)this.width=500'>      ftype = @new_file.content_type.strip500)this.width=500'>      if ! MIME_TYPES.include?(ftype)500)this.width=500'>        @errorNumber = 202500)this.width=500'>        puts "#{ftype} is invalid MIME type"500)this.width=500'>        raise "#{ftype} is invalid MIME type"500)this.width=500'>      else500)this.width=500'>        path = date_directory_path + "/" + @new_file.original_filename500)this.width=500'>        File.open(path,"wb",0664) do |fp|500)this.width=500'>          FileUtils.copy_stream(@new_file, fp)500)this.width=500'>        end500)this.width=500'>        @errorNumber = 0500)this.width=500'>      end500)this.width=500'>    rescue => e500)this.width=500'>      @errorNumber = 110 if @errorNumber.nil?500)this.width=500'>    end500)this.width=500'>    500)this.width=500'>    # Fix provided by Nicola Piccinini -- http://superfluo.org500)this.width=500'>    render :text => %Q'<script>window.parent.OnUploadCompleted(#{@errorNumber},\"#{UPLOADED}/#{params[:Type]}/#{Time.now.year}/#{Time.now.month}/#{@new_file.original_filename}\",\"#{@new_file.original_filename}\",\"\");</script>'500)this.width=500'>  end 500)this.width=500'>  private500)this.width=500'>  def date_directory_path500)this.width=500'>    base_dir = "#{UPLOADED_ROOT}/#{params[:Type]}/#{Time.now.year}/#{Time.now.month}"500)this.width=500'>    #Dir.mkdir(base_dir,0775) unless File.exists?(base_dir)500)this.width=500'>    FileUtils.mkdir_p base_dir500)this.width=500'>    "#{base_dir}"500)this.width=500'>  end500)this.width=500'>7.同理可以对其上传文件名称进行随机处理以防重名,就不多说了。做此笔记,抛砖引玉。发现rails的plugin机制挺不错的,比较灵活,不过网上介绍plugin的文章真的不是很多


阅读全文(2318) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.328 second(s), page refreshed 144753009 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号