Class: Headmin::Form::AssociationView
Defined Under Namespace
Classes: AssociationDoesNotExistError
Instance Method Summary
collapse
Methods inherited from ViewModel
#attributes, #initialize, #to_hash
Constructor Details
This class inherits a constructor from ViewModel
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class ViewModel
Instance Method Details
#attribute_with_id ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'app/models/headmin/form/association_view.rb', line 39
def attribute_with_id
attribute_with_id = collection? ? "#{association_foreign_key}s" : foreign_key
if attribute_with_id.nil?
raise(AssociationDoesNotExistError, "Association attribute that was passed does not exist.")
else
attribute_with_id
end
end
|
#collection ⇒ Object
49
50
51
|
# File 'app/models/headmin/form/association_view.rb', line 49
def collection
association_class.all.map { |item| [item.to_s, item.id] }
end
|
21
22
23
24
25
|
# File 'app/models/headmin/form/association_view.rb', line 21
def input_group_options
default_input_group_options
.deep_merge(label_input_group_options)
.deep_merge(@input_group || {})
end
|
12
13
14
15
16
17
18
19
|
# File 'app/models/headmin/form/association_view.rb', line 12
def input_options
keys = attributes - %i[append attribute collection float form input_group include_blank label prepend validate selected tags wrapper]
options = to_h.slice(*keys)
def_input_options = default_input_options
def_input_options = def_input_options.deep_merge(options)
def_input_options = def_input_options.merge({multiple: true}) if collection?
def_input_options
end
|
#select_options ⇒ Object
33
34
35
36
37
|
# File 'app/models/headmin/form/association_view.rb', line 33
def select_options
keys = %i[include_blank selected]
options = to_h.slice(*keys)
default_options.deep_merge(options)
end
|
#wrapper_options ⇒ Object
27
28
29
30
31
|
# File 'app/models/headmin/form/association_view.rb', line 27
def wrapper_options
default_wrapper_options.deep_merge({
class: ["mb-3", ("form-floating" if float)]
}).deep_merge(@wrapper || {})
end
|