class Slices::CmsFormBuilder

Constants

FIELD_ERROR_PROC

Private Instance Methods

with_custom_field_error_proc() { || ... } click to toggle source
# File lib/slices/cms_form_builder.rb, line 33
def with_custom_field_error_proc(&block)
  default_field_error_proc = ::ActionView::Base.field_error_proc
  ::ActionView::Base.field_error_proc = FIELD_ERROR_PROC
  yield
ensure
  ::ActionView::Base.field_error_proc = default_field_error_proc
end
wrap_field(selector, attribute, options) click to toggle source
# File lib/slices/cms_form_builder.rb, line 18
def wrap_field(selector, attribute, options)
  with_custom_field_error_proc do
    content = send(selector, attribute, options)
    options = {}
    errors = @object.errors[attribute]

    if errors.any?
      options[:class] = 'error'
      content << @template.send(:content_tag, :p, errors.join(' and '))
    end

    @template.content_tag(:li, label(attribute) + content, options)
  end
end