Module: ViewComponent::ComponentHelper

Overview

To be used only within a component class such as ButtonComponent

Instance Method Summary collapse

Instance Method Details

#class_list(base, *styles) ⇒ Object



6
7
8
9
# File 'app/helpers/view_component/component_helper.rb', line 6

def class_list(base, *styles)
  base.concat(styles.compact)
  base.join(' ')
end

#resolve_error(form, name, explicit_error) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'app/helpers/view_component/component_helper.rb', line 11

def resolve_error(form, name, explicit_error)
  return explicit_error if explicit_error.present?
  return if form.blank? || form.object.blank? || name.blank?

  attribute = name.to_s.split('[').last.delete(']').humanize
  message = form.object.errors[name].first

  message.present? ? "#{attribute} #{message}" : nil
end