0.01
No commit activity in last 3 years
No release in over 3 years
Enum attributes with I18n and ActiveRecord support
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.1.4
>= 0
>= 12.3.3
>= 0

Runtime

 Project Readme

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

  1. Fork it ( https://github.com/ShuheiTsuji/enum_i18n_help )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request