What are the best options for Rich Text Editing in Rails?

前端 未结 7 1853
陌清茗
陌清茗 2020-12-28 16:33

I\'d like to use Rich Text Editing in place on forms in order to let admins change instructions. What are the best options for doing this?

[To be more clear - the

7条回答
  •  清酒与你
    2020-12-28 17:15

    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:

    1. There is a typo under "Usage", <% yield :head %> should be <%= yield :head %>
    2. 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 the puny_mce call. This makes sense -- the include_puny_mce is instructing the page on which javascripts it needs, and the puny_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 %>
    
    

    New post

    <% form_for(@post) do |f| %> <%= f.error_messages %> <%= f.label :title, "Title" %>
    <%= f.text_field :title %>
    <%= f.label :content, "Post Content" %>
    <%= f.text_area :content, :cols => 100 %> <%= puny_mce 'post_content', 'post_content', :profile => :full %>

    <%= f.submit 'Create' %>

    <% end %>

    I hope this helps!

提交回复
热议问题