-
-
Save abevoelker/fed59c2ec908de15acd27965e4725762 to your computer and use it in GitHub Desktop.
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
# app/helpers/application_helper.rb | |
module ApplicationHelper | |
def human_enum_name(model, attr) | |
I18n.t("activerecord.attributes.#{model.model_name.i18n_key}.#{attr.to_s}.#{model.send(attr)}") | |
end | |
end | |
# human_enum_name(@user, :status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very helpful, I just suggest to add something to the
#{attr.to_s}
key in your helper, like#{attr.to_s}_types
otherwise you can't use the human attribute method as it will have the hash instead a string and will mark an error, example: