簡體   English   中英

帶有 Ckeditor 和 Cocoon 附加富文本編輯器的 Rails 嵌套屬性不顯示

[英]Rails nested attributes with Ckeditor and Cocoon additional rich text editors don't show up

我有一個嵌套的屬性表單,它使用Ckeditor gem 和 Simple 表單來構建具有多個富文本編輯器的表單。 一個用於Body文本編輯器和一個用於Footer文本編輯器。

在此處輸入圖片說明

關系是body has many footers

我想讓用戶添加任意​​數量的頁腳。 為了實現這一點,我使用了Cocoon gem 當用戶單擊Add additional footer一個表單,問題是它不是一個Ckeditor rich text editor只是一個常規表單。

在此處輸入圖片說明

形式

= f.simple_fields_for :footers do |footer|
  = render 'footer_fields', f: footer
.links
  = link_to_add_association 'Add Additional Footer', f, :footers

部分的

  = f.input :content, label: 'Footer', as: :rich_text_mergefields, input_html: {class: 'span12'}

無論如何,是否可以使用 Cocoon 或其他任何方式即時添加Ckeditor文本區域?

我最終做了以下事情,希望它在未來對某人有所幫助。

= f.input :content, label: 'Footer', as: :rich_text_mergefields, input_html: { class: 'span12 footer-field'}


$('#owner').on('cocoon:after-insert', function(_, element) {
   id = $(element).index() + '_footer'
   text_area = $(element[0]).find('.footer-field').attr('id', id);
   config = $(element[0]).find('.footer-field').data('ckeditorOptions');
   CKEDITOR.replace(id, config);
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM