---
title: "Rich online editor for Ruby on Rails - tinyMCE"
author: "jacky"
date: "2008-07-29T23:40:18Z"
tags: []
slug: "rich-online-editor-for-ruby-on-rails-tinymce"
draft: false
lastmod: "2008-07-29T23:40:18Z"
id: 221331
url: "https://jacky.iteye.com/blog/221331"
---

<http://www.aidanf.net/adding-a-rich-text-editor-to-your-rails-application> 推荐两款for rails的rich editor. 
今日尝试了一下以前在java里使用过的TinyMCE。


> ruby script/plugin install hxxp://secure.near-time.com/svn/plugins/trunk/tiny_mce/
> 


> rake tiny_mce:scripts:install

在controller里配置editor的属性：

```ruby

class UsersController < ApplicationController
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])
```

而后在view中任意使用textarea的属性，都会出现一个Rich editor.

```ruby

<% # Include TinyMCE before other JS to avoid problems -%>
<%= javascript_include_tiny_mce_if_used %>
<%= tiny_mce if using_tiny_mce? %>

<%= f.text_area :user_name %>
```

似乎不能只针对一个属性。
更多请看：
<http://tinymce.moxiecode.com/index.php>