Search code examples
ruby-on-railsckeditoractiveadminckeditor4.x

CKEditor on custom page in activeadmin


i got the following issue:

I want to add a form on a custom page (no model) to design an email for mailjet. I already got a custom page and a form with an CKEditor input and an input for the subject. But the subject field isn't shown on the page.

This is my code:

ActiveAdmin.register_page "Mail", namespace: :lku do

  def send_mail

  end

  content do
    panel 'Write mail' do

      semantic_form_for :mail, :url => "lku/send_mail", method: :post do |f|

        f.inputs do
          f.input :subject, :input_html => { :name => 'subject' }
        end
        f.inputs do

        f.input :text, as: :ckeditor, :input_html => { :name => 'text' }
        end
      end
    end
  end
end

And this is the result:

ckeditor without subject field

When I add

f.actions

it looks like this

just submit button

can someone help me please?


Solution

  • I was able to reproduce the problem without having ckeditor. Only the last element of form would display.

    I don't know exactly what's going on, but it has something to do with how Arbre renders the content you generate inside the content block.

    My solution is this

    1. Transform the form content into .erb and move the form under views/lku/mail/_mailform.html.erb

      <%= semantic_form_for :mail do |f| %>
        <%= f.inputs do %>
          <%= f.input :subject %>
          <%= f.input :text %>
        <% end %>
        <%= f.actions %>
      <% end %>
      
    2. Include the form in the page

      content do
        panel 'Write mail' do
          render partial: 'mailform'      
        end
      end
      

    See if you can still mount the editor by using regular Rails form helpers - https://github.com/galetahub/ckeditor#form-helpers