Created
May 10, 2017 17:32
-
-
Save nononoy/5fdf50e337cca5965444f5c57ac494b6 to your computer and use it in GitHub Desktop.
EnumI18nHelper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module EnumI18nHelper | |
def enum_options_for_select(class_name, enum) | |
class_name.send(enum.to_s.pluralize).map do |key, _| | |
[enum_i18n(class_name, enum, key), key] | |
end | |
end | |
def enum_t(model, enum) | |
enum_i18n(model.class, enum, model.send(enum)) | |
end | |
def enum_i18n(class_name, enum, key) | |
I18n.t("activerecord.attributes.#{class_name.model_name.i18n_key}.#{enum.to_s.pluralize}.#{key}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment