Skip to content

Instantly share code, notes, and snippets.

@nononoy
Created May 10, 2017 17:32
Show Gist options
  • Save nononoy/5fdf50e337cca5965444f5c57ac494b6 to your computer and use it in GitHub Desktop.
Save nononoy/5fdf50e337cca5965444f5c57ac494b6 to your computer and use it in GitHub Desktop.
EnumI18nHelper
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