A form helper for the enum field of Rails model.
You can easily generate select tag which has enum field options.
Add this line to your application's Gemfile:
gem 'enum_select_rails'
class User
enum gender: {
female: 2,
male: 1,
other: 9
}
end
<%= f.enum_select :gender %>
Automatically apply i18n text into options text.
This feature is depends on enum_help.
# Gemfile
gem 'enum_help'
# application.rb
# i18n
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
# config/locales/models/user/ja.yml
ja:
activerecord:
models:
user: ユーザー
attributes:
user:
gender: 性別
enums:
user:
gender:
female: 女性
male: 男性
other: その他
The gem is available as open source under the terms of the MIT License.