Class: ActiveAdminAddons::EnumUtils
- Inherits:
-
Object
- Object
- ActiveAdminAddons::EnumUtils
- Defined in:
- lib/activeadmin_addons/support/enum_utils.rb
Class Method Summary collapse
- .options_for_select(klass, enum_name, use_db_value: false) ⇒ Object
- .translate_enum_option(klass, enum_name, enum_option_name) ⇒ Object
Class Method Details
.options_for_select(klass, enum_name, use_db_value: false) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/activeadmin_addons/support/enum_utils.rb', line 3 def self.(klass, enum_name, use_db_value: false) = klass.defined_enums[enum_name] .map do |enum_option_name, db_value| value = use_db_value ? db_value : enum_option_name [translate_enum_option(klass, enum_name, enum_option_name), value] end end |
.translate_enum_option(klass, enum_name, enum_option_name) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/activeadmin_addons/support/enum_utils.rb', line 11 def self.translate_enum_option(klass, enum_name, enum_option_name) return if enum_option_name.blank? klass_key = klass.model_name.i18n_key key = "activerecord.attributes.#{klass_key}.#{enum_name.pluralize}.#{enum_option_name}" I18n.t(key, default: enum_option_name) end |