EnumI18nHelp
Help ActiveRecord::Enum feature to work with I18n.
added a new Test::Unit to the existing EnumHelp gem and changed the namespace of I18n.
Installation
Add this line to your application's Gemfile:
gem 'enum_i18n_help'
And then execute:
$ bundle
Or install it yourself as:
$ gem install enum_i18n_help
Usage
model
class User < ActiveRecord::Base
enum role: { manager: 1, member: 2 }
end
I18n
ja:
activerecord:
attributes:
user/role:
manager: 管理者
member: 一般
en:
activerecord:
attributes:
user/role:
manager: Manager
member: Member
enum_column_text
user = User.first
user.role
=> "manager"
user.role_text
=> "管理者"
change locale
I18n.locale = :en
user.role
=> "manager"
user.role_text
=> "Manager"
enum_column_options
User.role_options
=> [["管理者", :manager], ["一般", :member]]
Contributing
- Fork it ( https://github.com/ShuheiTsuji/enum_i18n_help )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request