Class: Admin::SwitchComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
lib/generators/infold/templates/install/app/components/admin/switch_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(form, field, include_hidden: true) ⇒ SwitchComponent

Returns a new instance of SwitchComponent.



5
6
7
8
9
# File 'lib/generators/infold/templates/install/app/components/admin/switch_component.rb', line 5

def initialize(form, field, include_hidden: true)
  @form = form
  @field = field
  @include_hidden = include_hidden
end

Instance Method Details

#switchObject



11
12
13
14
15
# File 'lib/generators/infold/templates/install/app/components/admin/switch_component.rb', line 11

def switch
  classes = %W(form-check-input)
  classes << 'is-invalid' if helpers.admin_field_invalid?(@form, @field)
  @form.check_box(@field, class: classes.join(' '), include_hidden: @include_hidden)
end