【问题标题】:using ckeditor gem with rails nested attribute使用带有 rails 嵌套属性的 ckeditor gem
【发布时间】:2026-01-13 23:15:02
【问题描述】:

是否有人能够使用附加到嵌套表单中的表单构建器对象的 ckeditor gem (https://github.com/galetahub/ckeditor/issues/98)?

宝石文件:

gem 'rails', '3.2.1'
....
gem "nested_form"
gem "ckeditor", "3.7.0.rc3"

我将问题提取到一个非常简单的嵌套表单应用程序中,即

post.rb:

has_many :comments
accepts_nested_attributes_for :comments

所以我尝试使用 ckeditor 来编辑 cmets。视图如下所示:

<%= nested_form_for(@post) do |f| %>

<%= f.label :post_content %>

<%= f.text_area :post_content %>
<%= f.fields_for :comments do |cf| %>
<%= cf.cktext_area :comment_content %>
<% end %>
....

评论内容会出现一个普通的文本区域。如果我将表单的帖子部分中的“f.text_area”切换为“f.cktext_area”,则会为帖子内容显示 ckeditor。

呈现表单时,日志中不会出现错误。

我错过了什么吗?

【问题讨论】:

    标签: ruby-on-rails ckeditor nested-forms nested-attributes formbuilder


    【解决方案1】:

    您是否生成了 ckeditor 文件:

    rails generate ckeditor:models --orm=active_record --backend=paperclip
    

    【讨论】: