Class: Cms::FormBuilder::ContentBlockFormBuilder

Inherits:
SimpleForm::FormBuilder
  • Object
show all
Includes:
DeprecatedInputs
Defined in:
lib/cms/form_builder/content_block_form_builder.rb

Overview

Adds additional methods to the forms for creating content blocks.

Instance Method Summary collapse

Methods included from DeprecatedInputs

#cms_drop_down, #cms_file_field, #cms_text_editor, #cms_text_field, #template_editor

Instance Method Details

#cms_attachment_managerObject

Allows editors to add multiple files uploader for attachments. Usage:

<%= f.attachment_manager %>

Generator: The following will generate an attachments field with an associated attachment manager input.

rails generate cms:content_block Widget photos:attachments


15
16
17
# File 'lib/cms/form_builder/content_block_form_builder.rb', line 15

def cms_attachment_manager
  input :attachments, as: :attachments
end

#cms_error_messagesObject

Displays a concise list of error messages. This is may be unnecessary given that simple form will display error inline. Handles ‘global’ messages that aren’t specific to a field.



32
33
34
35
36
37
38
39
40
41
# File 'lib/cms/form_builder/content_block_form_builder.rb', line 32

def cms_error_messages
  return unless object.respond_to?(:errors) && object.errors.any?

  errors_list = ""
  errors_list << @template.(:h2, "#{object.errors.size} error prohibited this #{object_name.humanize} from being saved.".html_safe)
  errors_list << @template.(:p, "There were problems with the following fields:")
  errors_list << @template.(:ul, object.errors.full_messages.map { |message| @template.(:li, message).html_safe }.join("\n").html_safe).html_safe

  @template.(:div, errors_list.html_safe, :class => "errorExplanation", :id => "errorExplanation")
end

#cms_tag_list(options = {}) ⇒ Object

Allows editors add a space separated list of tags. Each tag entered will be created if needed as an instance of a Cms::Tag.

Usage:

<%= f.cms_tag_list %>

There is no generator for this field type.



26
27
28
# File 'lib/cms/form_builder/content_block_form_builder.rb', line 26

def cms_tag_list(options={})
  input :tag_list, as: :tag_list, label: "Tags", input_html: {autocomplete: 'off'}, hint: "A space separated list of tags."
end