ActiveRecord Humanized Enum (I18n)
Easily translate your Active Record's enums.
Installation
Include to your Gemfile
gem 'activerecord_humanized_enum', require: 'active_record/humanized_enum'
Usage
ActiveRecord integration
The installation automatically self-includes in the ActiveRecord::Base
.
How to use
- Call the
enum
macro method just like you already do:
class User
enum status: [:enabled, :disabled]
end
- Translate the enums in your YML translation files:
pt-BR:
activerecord:
attributes:
user:
status: Estado
statuses:
enabled: Ativo
disabled: Inativo
- Will be available the following methods:
User.humanized_status(:enabled)
User.humanized_status(:disnabled)
user = User.first
puts user.status
puts user.humanized_status
user.status = :disabled
puts user.humanized_status
Maintainer
Dhyego Fernando