Class: Administrate::Field::Select
- Inherits:
-
Base
- Object
- Base
- Administrate::Field::Select
show all
- Defined in:
- lib/administrate/field/select.rb
Instance Attribute Summary
Attributes inherited from Base
#attribute, #data, #options, #page, #resource
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
associative?, eager_load?, field_type, html_class, #html_class, #initialize, #name, permitted_attribute, #read_value, #required?, #to_partial_path, with_options
Class Method Details
.searchable? ⇒ Boolean
6
7
8
|
# File 'lib/administrate/field/select.rb', line 6
def self.searchable?
true
end
|
Instance Method Details
#active_record_enum? ⇒ Boolean
31
32
33
|
# File 'lib/administrate/field/select.rb', line 31
def active_record_enum?
resource.class.defined_enums.key?(attribute.to_s)
end
|
#active_record_enum_values ⇒ Object
35
36
37
|
# File 'lib/administrate/field/select.rb', line 35
def active_record_enum_values
resource.class.defined_enums[attribute.to_s].map(&:first)
end
|
#html_controller ⇒ Object
39
40
41
|
# File 'lib/administrate/field/select.rb', line 39
def html_controller
"select"
end
|
#include_blank_option ⇒ Object
27
28
29
|
# File 'lib/administrate/field/select.rb', line 27
def include_blank_option
options.fetch(:include_blank, false)
end
|
#selectable_options ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/administrate/field/select.rb', line 10
def selectable_options
values =
if options.key?(:collection)
options.fetch(:collection)
elsif active_record_enum?
active_record_enum_values
else
[]
end
if values.respond_to? :call
values = values.arity.positive? ? values.call(self) : values.call
end
values
end
|