An enum-type attribute with support for I18n and ActiveRecord / Mongoid / MongoMapper / Sequel. It is used when you want to classify a model by status.
gem 'enumerize'
Also execute this.
$ bundle install
class User
extend Enumerize
enumerize :sex, in: [:male, :female]
end
ja:
enumerize:
user:
sex:
male:Man
female:woman
--If you want to output the value
User.sex.values # => ["male", "female"]
User.sex.options # => [["Man", "male"], ["woman", "female"]]
user = User.new
user.sex_value # => "male"
user.sex_text # => "Man"
--If you want to use it as a select box
<%= form_for @user do |f| %>
<%= f.select :sex, User.sex.options %>
<% end %>
How to use Enumerize with Rails
Translated the README for gem enumerize
Recommended Posts