子在川上曰

  逝者如斯夫不舍昼夜
随笔 - 71, 文章 - 0, 评论 - 915, 引用 - 0
数据加载中……

在Rails中使用FCKeditor插件实现WEB富文本编辑

比如象BlogJava这里编辑器就应该是用的FCKeditor ,FCKeditor 相当有名,它有PHP、JSP、rails等多个版本,核心都是一些javascript代码。

文/陈刚  (www.chengang.com.cn)

环境:ubuntu linux 7.0.4  +  ruby 1.8.5 + Rails 1.2.3 + FCKeditor 0.4.1

直接从它的subversion库里取得该Rails插件。先进入到你的项目根目录,再执行如下命令
ruby script/plugin install svn://rubyforge.org/var/svn/fckeditorp/trunk/fckeditor

其他说明:
(1)你的linux必须先安装了subversion。(ubuntu里用新立得搜subversion即得)
(2)把命令中的install 改为 destory,可以删除安装。
(3)我取到的是2007年4月份最后更新的, v 0.4.1版
(4)FCKeditor安装在项目根目录下的vendor/plugins/fckeditor 里,
(5)vendor/plugins/fckeditor里的README很值得一读,我碰到Ajax问题,查了所以网上的中文资料都没有提到,在这个README却有。


用如下语句在页面里含入它的javascript库
<%= javascript_include_tag :fckeditor %>  

<%= javascript_include_tag "fckeditor/fckeditor" %>


在需要富文本的Form表单用如下语句生成一个富文件编辑框:
<%= fckeditor_textarea("topic""content", :toolbarSet => 'Simple', :width => '100%', :height => '200px') %>

说明:topic对应模型对象,content对应它的字段。也就是要求当前页要有@topic这个实例变量。


如果是用了ajax,则需要在form_remote_tag加上一个before项
  <%= form_remote_tag(:update => update,
                      :before 
=> fckeditor_before_js('topic', 'content'),
                      :url 
=> {:controller => 'topics', :action => 'create', :template => 'show'} )%>

并且富文件编辑框要加一个ajax=true的选项:
<%= fckeditor_textarea(:topic, :content, :ajax => true:toolbarKit => 'Simple', :width => '100%', :height => '600px') %>





在使上传图片的功能时碰到了错误。弹出出alert对话框,显示:Error on file upload.Error number: 403

在日志里显示如下,表面上看好象是路由配置的问题

ActionController::RoutingError (no route found to match "/fckblank.html" with {:method=>:get}):
/var/lib/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1292:in `recognize_path'
/var/lib/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1282:in `recognize'
/var/lib/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:40:in `dispatch'
/var/lib/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:113:in `handle_dispatch'
/var/lib/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:79:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'


最后在http://blog.caronsoftware.com/articles/2006/12/03/fckeditor-0-4-0-released#comment-1745找到了答案,这是一个BUG

解决方法 :

修改:vendor/plugins/fckeditor/app/controller/fckeditor_controller.rb
将原来的

unless "#{file.class}" == "Tempfile"

改为
unless "#{file.class}" == "Tempfile" || "#{file.class}" == "StringIO"



posted on 2007-08-25 16:44 陈刚 阅读(2323) 评论(2)  编辑  收藏 所属分类: Rails&Ruby

评论

# re: 在Rails中使用FCKeditor插件实现WEB富文本编辑  回复  更多评论   

bu cuo
2008-04-20 17:04 | lii

# re: 在Rails中使用FCKeditor插件实现WEB富文本编辑  回复  更多评论   

顶一个,最后的那个bug最近的版本已经有修正。。。
2009-07-24 10:11 | ycc

只有注册用户登录后才能发表评论。


网站导航: