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:
- Grab and install the TinyMCE plugin for Rails.
- 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.
- 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.
3 Comments
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
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
> useful to somebody
Well it was useful to me. Keep it up. May your Google-Ads pay billions!