Module: SMEditor::Rails::FormHelper
- Defined in:
- lib/smeditor/rails/form_helper.rb
Overview
View helper that mounts a SMEditor editor inside a Rails form.
<%= form.smeditor_editor :content %> # via FormBuilder
<%= smeditor_editor(form, :content) %> # standalone
Emits a hidden field carrying the document HTML plus an empty mount point. The boot script (smeditor.js) finds the mount, attaches a real editor seeded from the hidden field, and writes editor.getHTML() back into that field on every change — so a normal form submit persists the content with no extra wiring.
Instance Method Summary collapse
-
#smeditor_editor(form, method, options = {}) ⇒ Object
form - a Rails FormBuilder method - the model attribute (stored as an HTML string) options - :kit ("starter" | "full"), :class, :placeholder, :upload_url.
Instance Method Details
#smeditor_editor(form, method, options = {}) ⇒ Object
form - a Rails FormBuilder method - the model attribute (stored as an HTML string) options - :kit ("starter" | "full"), :class, :placeholder, :upload_url
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/smeditor/rails/form_helper.rb', line 19 def smeditor_editor(form, method, = {}) object = form.object current = object.respond_to?(method) ? object.public_send(method) : nil kit = ([:kit] || SMEditor.config.default_kit).to_s upload_url = .fetch(:upload_url, smeditor_upload_url) hidden = form.hidden_field( method, value: current.to_s, data: { smeditor_input: true }, ) mount = content_tag( :div, "", class: "smeditor-mount", data: { smeditor: true, smeditor_kit: kit, smeditor_placeholder: [:placeholder], smeditor_upload_url: upload_url, }, ) wrapper_class = ["smeditor-field", [:class]].compact.join(" ") content_tag(:div, safe_join([hidden, mount]), class: wrapper_class) end |