2006年11月25日星期六

TinyMCE (WYSIWYG) for Ruby on Rails

1. 首先在https://secure.near-time.com/svn/plugins/trunk/tiny_mce/上下载Blake Watters制作的TinyMCE Plugin,放在vendor/plugins/目录下 。
2. 重新启动服务
3. 在Controller下加上uses_tiny_mce就可以把所有的textarea都加上tinyMCE编辑器了。
如果想在特定的action下加特定样式的TinyMCE用下面的代码


uses_tiny_mce(:options => {:theme => 'advanced',
:browsers => %w{msie gecko},
:theme_advanced_toolbar_location => "top",
:theme_advanced_toolbar_align => "left",
:theme_advanced_resizing => true,
:theme_advanced_resize_horizontal => false,
:paste_auto_cleanup_on_paste => true,
:theme_advanced_buttons1 => %w{formatselect fontselect fontsizeselect
bold italic underline strikethrough separator
justifyleft justifycenter justifyright indent
outdent separator bullist numlist forecolor
backcolor separator link unlink image undo redo
}
,
:theme_advanced_buttons2 => [],
:theme_advanced_buttons3 => [],
:plugins => %w{contextmenu paste}},
:only => [:new, :edit, :show, :index])

4. 如果要使用AJAX的form还需要加上一行:before => 'tinyMCE.triggerSave(true,true)',比如
<%= submit_to_remote "savbtn","Store...", :url => { :action => 'savepressrelease' }, :before => 'tinyMCE.triggerSave(true,true)', :update => 'jshold', :complete => "Element.show('addrelink')" %>

0 评论: