---
title: " FCKeditor插件实现富文本编辑 "
author: "xinlanzero"
date: "2011-08-03T13:23:15Z"
tags: []
categories: ["Web前端"]
slug: "fckeditor"
draft: false
lastmod: "2011-08-03T13:23:15Z"
id: 1138993
url: "https://xinlanzero.iteye.com/blog/1138993"
---

首先下载

Ruby代码 [![复制代码](http://xinlanzero.iteye.com/images/icon_copy.gif)](http://xinlanzero.iteye.com/admin/blogs/ "复制代码") [![收藏代码](http://xinlanzero.iteye.com/images/icon_star.png)![](http://xinlanzero.iteye.com/images/spinner.gif)]()

1. ruby script/plugin install svn://rubyforge.org/var/svn/fckeditorp/trunk/fckeditor

其他说明：  
(1)FCKeditor安装在项目根目录下的vendor/plugins/fckeditor 里，  
(2)README文件代有使用说明

在你要使用是视图上添上

Ruby代码 [![复制代码](http://xinlanzero.iteye.com/images/icon_copy.gif)](http://xinlanzero.iteye.com/admin/blogs/ "复制代码") [![收藏代码](http://xinlanzero.iteye.com/images/icon_star.png)![](http://xinlanzero.iteye.com/images/spinner.gif)]()

1. &lt;%= javascript\_include\_tag :fckeditor %&gt;

或

Ruby代码 [![复制代码](http://xinlanzero.iteye.com/images/icon_copy.gif)](http://xinlanzero.iteye.com/admin/blogs/ "复制代码") [![收藏代码](http://xinlanzero.iteye.com/images/icon_star.png)![](http://xinlanzero.iteye.com/images/spinner.gif)]()

1. &lt;%= javascript\_include\_tag "fckeditor/fckeditor" %&gt;

在需要富文本的Form表单用如下语句生成一个富文件编辑框：

Ruby代码 [![复制代码](http://xinlanzero.iteye.com/images/icon_copy.gif)](http://xinlanzero.iteye.com/admin/blogs/ "复制代码") [![收藏代码](http://xinlanzero.iteye.com/images/icon_star.png)![](http://xinlanzero.iteye.com/images/spinner.gif)]()

1. &lt;%= fckeditor\_textarea("object", "field", :toolbarSet =&gt; 'Simple', :width =&gt; '100%', :height =&gt; '200px') %&gt;

说明：object对应模型对象,field对应它的字段。

如果是用了ajax，则需要在form\_remote\_tag加上一个before项

Ruby代码 [![复制代码](http://xinlanzero.iteye.com/images/icon_copy.gif)](http://xinlanzero.iteye.com/admin/blogs/ "复制代码") [![收藏代码](http://xinlanzero.iteye.com/images/icon_star.png)![](http://xinlanzero.iteye.com/images/spinner.gif)]()

1. &lt;%= form\_remote\_tag(:update =&gt; update,
2. :before =&gt; fckeditor\_before\_js('topic', 'content'),
3. :url =&gt; {:controller =&gt; 'topics', :action =&gt; 'create', :template =&gt; 'show'} )%&gt;

并且富文件编辑框要加一个ajax=true的选项：

Ruby代码 [![复制代码](http://xinlanzero.iteye.com/images/icon_copy.gif)](http://xinlanzero.iteye.com/admin/blogs/ "复制代码") [![收藏代码](http://xinlanzero.iteye.com/images/icon_star.png)![](http://xinlanzero.iteye.com/images/spinner.gif)]()

1. &lt;%= fckeditor\_textarea(:topic, :content, :ajax =&gt; **true**, :toolbarKit =&gt; 'Simple', :width =&gt; '100%', :height =&gt; '600px') %&gt;