TinyMCE, Rails and YouTube

I don’t know how many people out there care, but I guess little tidbits of information like this end up useful to somebody, eventually (thanks, Google).

Yesterday I had to fulfill the following requirements: create a Ruby on Rails CMS where a user can enter a stylized description without knowing HTML, BUT can also embed a YouTube video when necessary.

Here’s the solution:

  1. Grab and install the TinyMCE plugin for Rails.
  2. Use the following code in your controller:

    uses_tiny_mce(:options => {:theme => ‘advanced’,
    :extended_valid_elements => “object[classid|codebase|width|height|align],
    param[name|value],
    embed[quality|type|
    pluginspage|width|height|src|align|wmode]”
    })

    The advanced theme mode ensures that you have an “HTML” mode in your TinyMCE editor, and can therefore paste YouTube code. The extended_valid_elements attribute is essential and tells TinyMCE to avoid stripping out those tags. The full API for TinyMCE is here.

  3. Unfortunately, there is a bug in the version of TinyMCE used by the plugin. You will see that your embed tag is stripped out, despite the extended_valid_elements attribute. The solution is easy. First, grab the latest version of TinyMCE. Then, go into the public\javascripts\tiny_mce directory of your app and replace these files with the newer ones: tiny_mce.js, tiny_mce_popup.js, and tiny_mce_src.js.

You should be all set.

This entry was posted in Technology. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Justin
    Posted July 31, 2007 at 6:38 pm | Permalink

    I wish I was, but I am not all set. I have basically the exact same setup as you’ve listed and my embed tags get HTML escaped on me still. By the “latest version of TinyMCE” do you mean 2.1.1.1? Thanks

  2. Posted August 23, 2007 at 7:20 pm | Permalink

    There’s actually a YouTube plugin for TinyMCE that we’ve been able to use successfully, if you’re interested.

    http://sourceforge.net/tracker/index.php?func=detail&aid=1669296&group_id=103281&atid=738747

    We’ve also been able to create an image selector for TinyMCE so that our users can select from a list of previously uploaded images, instead of copying and pasting URLs.

    Hopefully, we can return the favor with our How-To as well! How to Create an Image Selection Plugin for tinyMCE with Ruby on Rails

  3. Kalessin
    Posted September 5, 2007 at 3:58 pm | Permalink

    > useful to somebody

    Well it was useful to me. Keep it up. May your Google-Ads pay billions!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>