Rails 4 Active Record Enums are great, but what is the right pattern for translating with i18n?
相关问题
- Strong parameter override for DeviseTokenAuth cont
- Mechanize getting “Errno::ECONNRESET: Connection r
- What is the fastest for Map keys: Enum.valueOf(~)
-
undefined method `type_cast' for #
- Switch String with Enum variables
相关文章
- Enum with associated value conforming to CaseItera
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Why do I have to cast enums to int in C#?
- Why doesn't reflections.getSubTypesOf(Object.c
- How can I get enum possible values in a MySQL data
- Bind a char to an enum type
- ClassLoad an Enum type
The model:
The locale file:
Usage:
You can simply add a helper:
and set it up as usually:
then use it with your select:
my_something_list
Yet another way, I find it a bit more convenient using a concern in models
Concern :
YML:
View :
Don't forget to add concern in your model :
Here is a view:
Here is a model (you can move this code into a helper or a decorator actually)
And here is locale file:
Try the enum_help gem. From its description:
Elaborating on user3647358's answer, you can accomplish that very closely to what you're used to when translating attributes names.
Locale file:
Translate by calling I18n#t: