[英]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.