3

我已将 CKEditor 集成到我的博客评论系统中,当我加载新页面时它显示良好。

但是,对于回复评论,我有一个 javascript 操作,可以从每个评论下方的“回复此评论”链接打开一个新的评论表单。在这种情况下,CKEditor 不会加载(我只是得到一个基本的非 CKEditor 文本区域)。我是否需要在我的 javascript 文件中添加一些内容以便 CKeditor 正确加载?

帖子/show.html.erb

<%= @post.content %>
<%= render 'comments/form' %> #this CKEditor form renders fine when the page loads
<%= @post.comments %>

评论/_form.html.erb

<%= simple_form_for(@comment, remote: true) do |f| %>
  <%= f.hidden_field :parent_id %>
  <%= f.cktext_area :content, :input_html => { :ckeditor => { :toolbar => 'Basic' } }, :class => "comment_input" %>
<%= f.button :submit %>

评论/new.js.erb

$('#comment_<%= @comment.parent.id %>').append("<%= escape_javascript(render 'form') %>");

评论/_comment.html.erb

<div id="comment_<%= comment.id %>">
  <%= comment.content.try(:html_safe) %>
  <%= link_to "reply to this comment", new_comment_path(:parent_id => comment), remote: true %>
</div>
4

1 回答 1

1

您必须创建编辑器的新实例。在 comments/new.js.erb 中附加表单后:

CKEDITOR.replace('id_of_textarea',{
    :toolbar => 'Basic'
});

我不确定是否可以使用任何选择器代替“id_of_textarea”。如果不是,则 textarea 必须具有唯一 ID。还有另一种创建编辑器实例的方法,但我自己没有尝试过

于 2013-01-23T21:46:34.200 回答