子在川上曰

            逝者如斯夫不舍晝夜
          隨筆 - 71, 文章 - 0, 評論 - 915, 引用 - 0

          導航

          隨筆分類(72)

          搜索

          •  

          積分與排名

          • 積分 - 591558
          • 排名 - 81

          最新評論

          閱讀排行榜

          在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 陳剛 閱讀(2355) 評論(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
          主站蜘蛛池模板: 汝南县| 北票市| 沁阳市| 富蕴县| 兴宁市| 漳州市| 麟游县| 历史| 镇安县| 高青县| 延川县| 莲花县| 全南县| 铜梁县| 林周县| 大方县| 亚东县| 柏乡县| 武义县| 金坛市| 雷波县| 正安县| 含山县| 句容市| 东乌| 凤山市| 华坪县| 柳江县| 岳西县| 五河县| 宝兴县| 罗田县| 齐齐哈尔市| 通州市| 通江县| 清河县| 建湖县| 梅河口市| 高雄县| 抚宁县| 酉阳|