Module: CKEditor5::Rails::Hooks::Form::FormBuilderExtension

Defined in:
lib/ckeditor5/rails/hooks/form.rb

Instance Method Summary collapse

Instance Method Details

#ckeditor5(method, options = {}) ⇒ Object

Creates a CKEditor 5 field for the specified form attribute.

Examples:

Basic usage

<%= form_for @post do |f| %>
  <%= f.ckeditor5 :content %>
<% end %>

With custom styling and required field

<%= form_for @post do |f| %>
  <%= f.ckeditor5 :content,
        style: 'width: 700px',
        required: true,
        initial_data: 'Hello World!'
  %>
<% end %>

Using custom preset and type

<%= form_for @post do |f| %>
  <%= f.ckeditor5 :content,
        preset: :custom,
        type: :inline,
        class: 'custom-editor'
  %>
<% end %>

Simple Form integration

<%= simple_form_for @post do |f| %>
  <%= f.input :content,
        as: :ckeditor5,
        input_html: { style: 'width: 600px' },
        required: true
  %>
<% end %>

Parameters:

  • method (Symbol)

    The model attribute to edit

  • options (Hash) (defaults to: {})

    Options for customizing the editor

Options Hash (options):

  • :preset (Symbol) — default: :default

    The preset configuration to use

  • :type (Symbol) — default: :classic

    Editor type (classic, inline, balloon, decoupled)

  • :config (Hash)

    Custom editor configuration

  • :initial_data (String)

    Initial content for the editor

  • :required (Boolean) — default: false

    Whether the field is required

  • :class (String)

    CSS classes for the editor

  • :style (String)

    Inline CSS styles



95
96
97
98
# File 'lib/ckeditor5/rails/hooks/form.rb', line 95

def ckeditor5(method, options = {})
  EditorInputBuilder.new(object_name, object, @template)
                    .build_editor(method, options)
end