FCKEditor是一个带有丰富功能的文本编辑器(text box),它和其他编辑器不同的在于它工作在Browser。它是一个开源项目,编写语言是javascript
下面介绍它是如何RoR一同工作的,可以在 http://www.fckeditor.net 下载到它的最新版本,我们先把下载文件中的:
/editor/
fckconfig.js
fckeditor.js
fckstyles.xml
fcktemplates.xml
拷贝到RoR architecture的javascript文件夹下
(public文件夹下建一个fckeditor文件夹,把上面所有文件放到fckeditor内,同时把除/editor/文件夹外的其它四个文件放到public/javascripts下面)
在需要FCKEditor的文件夹下面加入代码:
<%= javascript_include_tag "fckeditor" %>
<script type="text/javascript">
window.onload = function()
{
var oFCKeditor = new FCKeditor( 'product_intro' ) ;
oFCKeditor.ReplaceTextarea() ;
}
</script>
用户载入有关js文件,并且触发onload事件,这个事件会重置textarea
因此我们要加上:
<form action="/user/article" method="POST">
<TR bgColor=#ffffff><TD height=16 colspan="3">
<textarea id="MyTextarea" name="MyTextarea">This is <b>the</b> initial value.</textarea>
<input type="submit" value="提交文章">
</TD></TR></form>
运行结果就是:
使用起来上面的东西还算是有点麻烦,因为我们要先触发onload事件,然后写一个textarea,我们来增加一个helper method来提高我们的效率
在ApplicationHelper Module中加入method:
def fckeditor_text_field(object, method, options = {})
text_area(object, method, options ) +
javascript_tag( "var oFCKeditor = new FCKeditor('" + object + "_" + method + "');oFCKeditor.ReplaceTextarea()" )
end
这样我们就有了一个很好用的method,fckeditior_text_field,我们来使用它:
<%= javascript_include_tag "fckeditor" %>
<%= fckeditor_text_field "MyTextarea", "MyTextarea" %>
<%= submit_tag "提交文章" %>
就3句话,我们达到了同样的效果,很方便,这里我们设定的fckeditor_text_field 这个helper method,前两个arguments表示 text_area helper method 中的前两个arguments,用于表示<textarea>标签中的name属性的值,比如<%=fckeditor_text_field “a”,”b” %> 结果产生name=a[b]样式的<textarea>标签。这里说到了fckeditor_text_field helper method可以产生个textarea,因此我们就可以用处理textarea的方式来处理FCKEditor,比如:
def save
page = Page.new(params[:a])
page.save
end
这里保存的将是html格式的文本,在FCKEditor,我们选“源代码”按钮,结果就得到了我们保存的内容,也就是html格式的文本。
文章引用自: http://www.i170.com/user/killercat/Article_36350
分享到:
相关推荐
Integrating SystemC Models with Verilog and SystemVerilog.pdf
您将开始使用SignalR服务,并将其与Azure函数和Web应用程序集成。最后,您将在Azure函数上进行应用服务身份验证,并了解如何配置持续集成和交付到Azure功能。在阅读了这本书之后,您将能够理解使用Azure函数设计、...
Semantic Scene Completion via Integrating Instances and Scene In-the-Loop
Apress - Integrating Serverless Architecture.2019.epub
Eclipse BIRT主站上推荐的两本权威书籍有两本:1.BIRT: A Field Guide to Reporting 2.Integrating and Extending BIRT 第一本是BIRT报表开发的基本介绍,第二本将如何集成与扩展BIRT应用。这是第二本书的2008第二版
Integrating Python with Leading Computer Forensics Platforms 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Integrating Data & Services
NASA 应用遥感培训 (ARSET) NASA ARSET为灾害监测和其他遥感主题提供网络研讨会,其中许多使用地球引擎。 华盛顿大学 此页面具有出色的集科开发的入门教程的 凯瑟琳·库恩和吉利安Deines为电子科学研究所的...
经典教材.网络管理、开发人员以及有兴趣使用Cisco语音和数据集成产品的CCIE人员的必备参考书。
Integrating Voice and Data Networks (Keagy, ISBN# 1578701961)
Expand your imagination by letting go of the limitations of traditional animation mediums, software packages, or workflows and integrating 2D and 3D assets. With the updated and expanded second ...
David Silver RL Lecture 8 Integrating Learning and Planning
integrating skillPPT教案.pptx
这是2008年出版的新书,讲述BIRT(百灵)报表工具的使用方法。
[2010] Integrating CMMI and Agile Development - Case Studies and Proven Techniques for Faster Performance Improvement.(Paul E. McMahon).[0321714105].pdf Paperback: 368 pages Publisher: Addison-...
IHE是Integrating the ...IHE中国的基本原则是务实、开放和以应用为向导,欢迎国内各方面专家、各个与医疗信息化有关的学术团体及与医疗信息化相关的供应商、医院、学术机构、团体、研究院所等实体单位共同参与。
Integrating Python with Leading Computer Forensic Platforms takes a definitive look at how and why the integration of Python advances the field of digital forensics. In addition, the book includes ...
Integrating Direct3D 9.0 with MFC
Integrating Web Dynpro and SAP NetWeaver Portal
Integrating Opengear console servers into Zenoss monitoring