Class: CodengageViewComponents::ToggleComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- CodengageViewComponents::ToggleComponent
- Defined in:
- app/components/codengage_view_components/toggle_component.rb
Instance Method Summary collapse
-
#initialize(form: nil, attribute: nil, url: nil, value: nil, options: {}) ⇒ ToggleComponent
constructor
Uso: - Form mode: = render Form::ToggleComponent.new(form: f, attribute: :status, options: { id: "user-active-toggle" }).
Constructor Details
#initialize(form: nil, attribute: nil, url: nil, value: nil, options: {}) ⇒ ToggleComponent
Uso:
-
Form mode:
render Form::ToggleComponent.new(form: f, attribute: :status, options: { id: "user-active-toggle" })
-
Remote mode:
render Form::ToggleComponent.new(url: user_path(user), options: { method: :patch, enabled: user.active? })
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/components/codengage_view_components/toggle_component.rb', line 12 def initialize(form: nil, attribute: nil, url: nil, value: nil, options: {}) @form = form @attribute = attribute @url = url @value = value # Defaults centralizados aqui @id = .fetch(:id, nil) @disabled = .fetch(:disabled, false) @method = .fetch(:method, :patch) @enabled = .fetch(:enabled, false) @params = .fetch(:params, {}) @options = .except(:id, :value, :disabled, :method, :enabled, :params) validate_configuration! end |