What are the best options for Rich Text Editing in Rails?
I've gone through similar struggles in the past, and had settled on YUI. Unfortunately, YUI results (at least for me, and admittedly, I rushed through and never re-factored), in awful html.
Then tonight, when I stumbled on this post, I found PunyMCE. There are 2 awesome things about it: 1) its incredibly lightweight (as its name implies), and 2) there is a rails plugin that has already been created for it: puny_mce on github.
The documentation is good enough, except for a couple of things that I overlooked/had me scratching my head:
- There is a typo under "Usage", <% yield :head %> should be <%= yield :head %>
- If you want to use more
than the basic toolbar, you need to
include either a) the pre-setup
profile or b) the toolbar items and
required plugins for those items in
BOTH the
include_puny_mce
call AND thepuny_mce
call. This makes sense -- theinclude_puny_mce
is instructing the page on which javascripts it needs, and thepuny_mce
call is actually building the javascript output required to generate the rich editor.
Here is an example I put together to demonstrate:
<% content_for :head do %>
<%= include_puny_mce :profiles => [:full] %>
<% end %>
<h1>New post</h1>
<% form_for(@post) do |f| %>
<%= f.error_messages %>
<%= f.label :title, "Title" %><br />
<%= f.text_field :title %><br />
<%= f.label :content, "Post Content" %><br />
<%= f.text_area :content, :cols => 100 %>
<%= puny_mce 'post_content', 'post_content', :profile => :full %>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
I hope this helps!
I'm not sure if I fully understand the question, but if you just ask about which editor to use, there are many options and none of them is a matter of Rails - you can use any of them just by adding a little piece of javascript into your markup. Nice and up to date overview can be found here: http://bulletproofbox.com/web-based-rich-text-editors-compared/.
We started with TinyMCE but we are switching to Yahoo's Rich Text Editor because there were some weird issues with the way TinyMCE worked and because the Rich Text Editor documentation and default look-and-feel is superior.
Both are pretty easy to integrate with Rails (they are just JavaScript, after all). There are plugins, but you don't really need one.