Use of enums in rails
■ Improved readability of db, easy to manage ■ Application is also effective for Japanese localization
■ Mac OS catalina ■ Ruby on Rails (5.2.4.2) ■ Virtual Box:6.1 ■ Vagrant: 2.2.7
model/hoge.rb
① enum column name:[:Any word, :Any word, :Any word, :Any word]
② enum column name:{"Any word": 1,"Any word": 2.......}
hoge/_form.html.erb
<%= form.select :Column name,Model name.Column names.keys, :selected=>Model name.Column names[Column name] %>
that's all
■ About enum https://web-camp.io/magazine/archives/16862
■ About form_with https://qiita.com/tanaka-yu3/items/50f54f5d4f4b8dfe19f3
Recommended Posts