fckeditor富文本编辑器2.3.5安装使用

1、下载fckeditor

http://rubyforge.org/frs/?group_id=2038&release_id=23116

这里下载的是

fckeditor_plugin-0.5.1.tgz

2、创建一个新的RAILS项目,UseFckeditorDemo

3、脚手架创建一个

News title:string content:text

4、加压下载的文件到项目文件夹 /vender/plugins

5、重命名解压后的文件夹名字fckeditor_plugin-0.5.1为 fckeditor

6、修复rails与fck不兼容的问题,不修复会报"relative_url_root"不存的在错误

路径vendor/plugins/fckeditor/app/controllers/fckeditor_controller.rb

#uploaded = request.relative_url_root.to_s+"#{UPLOADED}/#{params[:Type]}" #取消掉此行

uploaded = ActionController::Base.relative_url_root.to_s+"#{UPLOADED}/#{params[:Type]}" #新增此行修复不兼容BUG

路径vendor/plugins/fckeditor/lib/fckeditor.rb

#js_path = "#{request.relative_url_root}/javascripts" #取消掉此行

js_path = "#{ActionController::Base.relative_url_root}/javascripts" #新增此行修复fck于rails不兼容问题

7、进入项目文件夹,安装FCKEDITOR

rake fckeditor:install

会在/public目录下,自动生成

目录uploads

目录public/javascripts/fckeditor

目录vendor/plugins/fckeditor

来存放上传的文件和一些文件.

8、然后布局app/views/layouts/news.html.erb调用

<%= javascript_include_tag :fckeditor %>

or

<%= javascript_include_tag 'fckeditor/fckeditor.js' %>

9、直接使用

在需要富文本的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') %>

首先去下载用plugin来实现此功能,有上传文件、拼写检查的功能等的fckeditor,下载最新版本即可.

http://rubyforge.org/frs/?group_id=2038

复制代码下载完,解压缩后起名字fckeditor然后放到项目的这个目录下

/vender/plugins

复制代码然后,安装

rake fckeditor:install

复制代码会在/public目录下,自动生成一个

目录uploads

目录public/javascripts/fckeditor

目录vendor/plugins/fckeditor

复制代码

来存放上传的文件和一些文件.

然后布局app/views/layouts/application.html.erb调用

<%= javascript_include_tag :fckeditor %>

复制代码

然后new.hrml.erb里

<%= fckeditor_textarea("article", "content", :toolbarSet => 'Simple', :width => '100%', :height => '200px') %>

<%= f.text_area :short_content %>

复制代码

替换为:

<%= fckeditor_textarea("article", "content", :toolbarSet => 'Simple', :width => '100%', :height => '200px') %>

复制代码

还有会有问题要修改2个地方参照,修复rails与fck不兼容的问题,不修复会报"relative_url_root"不存的在错误

http://github.com/salicio/fckeditor/commit/fcf8fbee8cfad3a3df0df50172e448727909ccb9

复制代码

路径vendor/plugins/fckeditor/app/controllers/fckeditor_controller.rb

#uploaded = request.relative_url_root.to_s+"#{UPLOADED}/#{params[:Type]}" #取消掉此行

uploaded = ActionController::Base.relative_url_root.to_s+"#{UPLOADED}/#{params[:Type]}" #新增此行修复不兼容BUG

复制代码

路径vendor/plugins/fckeditor/lib/fckeditor.rb

#js_path = "#{request.relative_url_root}/javascripts" #取消掉此行

js_path = "#{ActionController::Base.relative_url_root}/javascripts" #新增此行修复fck于rails不兼容问题

复制代码

具体配置支持ajax或者多个编辑器框可以参照 vendor/plugins/fckeditor/README


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值