tinymce

How to setup TinyMCE for Ruby on Rails 5

Posted by scott on June 08, 2008

UPDATE: the yui_editor from yahoo might be a better option. especially larsklevan’s yui_editor plugin for rails. it worked the first time, was way easier to setup and tinymce, and is still working great.

see new post on how to setup yui_editor

1. Install the plugin (instructions available on the rails wiki)

  • ruby script/plugin install http://secure.near-time.com/svn/plugins/trunk/tiny_mce/
  • rake tiny_mce:scripts:install
  • Put the following in your views:
  • Add it to whatever controller needs it:
    class MyController < ApplicationController
    uses_tiny_mce

And add this code in your view admin.rhtml or application.rhtml

<% # Include TinyMCE before other JS to avoid problems -%>
<%= javascript_include_tiny_mce_if_used %>
<%= tiny_mce if using_tiny_mce? %>

That’s actually it. It will work really nicely (tested on Rails 2.0.2 and ruby 1.8.6 on localhost)

Next, you’ll want to be able to add images inline style. Here’s a useful tutorial Part 1 and Part 2 for that.

Make sure foil XSS attacks MAKE A WHITELIST. Technoweenie is awesome.

Another helpful tutorial.


Keep in mind, you’ll need to restart your server.

Also, here’s a more custom setup for the uses_tiny_mce call in your controller. This is the setup I prefer.

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{bold italic strikethrough separator justifyleft justifycenter justifyright indent outdent separator bullist numlist separator link unlink separator undo redo },
                             :theme_advanced_buttons2 => [],
                             :theme_advanced_buttons3 => [],
                             :plugins => %w{contextmenu paste}},
                :only => [:new, :edit, :show, :index])

UPDATE JULY 10TH, 2008
You might have some issues with remote_for forms with tinymce. To solve the problem do something like this:

<% form_remote_for([:admin, Snippet.new], :before => "tinyMCE.triggerSave(true,true)") do |f| %>

Better yet, take a look at this awesome tutorial for how to use tinyMCE with AJAX in Rails