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:



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

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

#valueObject

Override value getter to handle multiple selection



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

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

#value=(new_value) ⇒ Object

Override value setter to handle multiple selection



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

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