在Rails中快速方便地使用Tiny mce编辑器

有了tiny_mce插件,使用HTML在线所见所得编辑器变得再简单不过了。

tiny_mce插件的地址:[url]http://github.com/kete/tiny_mce/tree/master[/url]

1.下载tiny_mce插件,放在RAILS_ROOT/verdor/plugin中,注意,要将tiny_mce插件目录命名为tiny_mce

2.[b]rake tiny_mce:install[/b]

3.在控制器中加上:uses_tiny_mce

class ArticlesController < ApplicationController
uses_tiny_mce
def new
@article = Article.new
end
end


4.在模板/layouts/application.html.erb头部加上[b]<%= include_tiny_mce_if_needed %>[/b]

5.在表单页面,为表单中的text area加上class为mceEditor,即可。

<%= f.text_area :body, :class => "mceEditor" %>


试试看,使用方便极了。


另外,对于Tiny Mce编辑器也可以自由定制各种配置选项,
如:

class ArticlesController < ApplicationController
uses_tiny_mce :options => {
:theme => 'advanced',
:language => 'zh',
:theme_advanced_resizing => true,
:theme_advanced_resize_horizontal => false,
:plugins => %w{ table fullscreen }
}
end

更多选项,请看tiny_mce插件目录中的tiny_mce_options.yml文件。

[color=red]更新:下面这个配置比较靠谱[/color]
uses_tiny_mce :options => {
:theme => 'advanced',
:language => 'zh',
:theme_advanced_resizing => true,
:theme_advanced_resize_horizontal => false,
:theme_advanced_toolbar_location => "top",
:theme_advanced_toolbar_align => "left",
:theme_advanced_buttons1 => %w{formatselect fontselect fontsizeselect forecolor backcolor bold italic underline strikethrough sub sup removeformat},
:theme_advanced_buttons2 => %w{undo redo cut copy paste separator justifyleft justifycenter justifyright separator indent outdent separator bullist numlist separator link unlink image media emotions separator table separator fullscreen},
:theme_advanced_buttons3 => [],
:theme_advanced_fonts => %w{宋体=宋体;黑体=黑体;仿宋=仿宋;楷体=楷体;隶书=隶书;幼圆=幼圆;Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats},
:plugins => %w{contextmenu paste media emotions table fullscreen}
}


还有比这使用更简单和易维护的么?

-------------分割线------------
[size=medium]Tiny Mce编辑器中文化[/size]

通过以上方式安装的编辑器是默认英文语言的,我们可以在
[url]http://tinymce.moxiecode.com/download_i18n.php[/url]下载中文语言包,解压后,覆盖相应的目录,然后在控制器中对uses_tiny_mce声明中加上[b]:language => 'zh'[/b]选项配置,这样就实现了Tiny Mce编辑器中文化

[img]http://qichunren.iteye.com/upload/picture/pic/33431/e3373e9d-44bc-3687-b3cb-014a658328c3.jpg[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值