Class: Alchemy::Ingredients::Select

Inherits:
Alchemy::Ingredient show all
Defined in:
app/models/alchemy/ingredients/select.rb

Overview

A text value from a select box

Constant Summary

Constants included from SearchableResource

SearchableResource::SEARCHABLE_COLUMN_TYPES

Instance Method Summary collapse

Methods inherited from Alchemy::Ingredient

allow_settings, allowed_settings, #as_editor_component, #as_view_component, #definition, #deprecated?, #has_tinymce?, #has_validations?, #linked?, normalize_type, #partial_name, #preview_ingredient?, #preview_text, related_object_alias, #settings, translated_label_for, #translated_role

Methods included from ConfigMissing

#const_missing

Methods included from SearchableResource

#ransackable_associations, #ransackable_attributes, #ransackable_scopes, #ransortable_attributes

Instance Method Details

#multiple?Boolean

Check if multiple selection is enabled in settings

Returns:



25
26
27
# File 'app/models/alchemy/ingredients/select.rb', line 25

def multiple?
  settings[:multiple] == true
end

#valueObject

Override value getter to handle multiple selection



14
15
16
17
# File 'app/models/alchemy/ingredients/select.rb', line 14

def value
  val = self[:value] || []
  multiple? ? val : val.first
end

#value=(new_value) ⇒ Object

Override value setter to handle multiple selection



20
21
22
# File 'app/models/alchemy/ingredients/select.rb', line 20

def value=(new_value)
  super(Array(new_value).compact_blank)
end