refactor(type de champ): extract codes_and_names method
This commit is contained in:
parent
7e3fc68c53
commit
8d0fffe44f
3 changed files with 8 additions and 2 deletions
|
@ -42,7 +42,7 @@ module Administrateurs
|
|||
|
||||
tdc_options = case tdc.type_champ
|
||||
when TypeDeChamp.type_champs.fetch(:departements)
|
||||
APIGeoService.departements.map { "#{_1[:code]} – #{_1[:name]}" }
|
||||
tdc.codes_and_names
|
||||
when TypeDeChamp.type_champs.fetch(:drop_down_list)
|
||||
tdc.drop_down_options.reject(&:empty?)
|
||||
end
|
||||
|
|
|
@ -108,7 +108,7 @@ class GroupeInstructeur < ApplicationRecord
|
|||
|
||||
options = case routing_tdc.type_champ
|
||||
when TypeDeChamp.type_champs.fetch(:departements)
|
||||
APIGeoService.departements.map { "#{_1[:code]} – #{_1[:name]}" }
|
||||
routing_tdc.codes_and_names
|
||||
when TypeDeChamp.type_champs.fetch(:drop_down_list)
|
||||
routing_tdc.options_with_drop_down_other
|
||||
end
|
||||
|
|
|
@ -477,6 +477,12 @@ class TypeDeChamp < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def codes_and_names
|
||||
if departement?
|
||||
APIGeoService.departements.map { "#{_1[:code]} – #{_1[:name]}" }
|
||||
end
|
||||
end
|
||||
|
||||
# historicaly we added a blank ("") option by default to avoid wrong selection
|
||||
# see self.parse_drop_down_list_value
|
||||
# then rails decided to add this blank ("") option when the select is required
|
||||
|
|
Loading…
Reference in a new issue