1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

enum で性別選択欄作ってみた

Posted at

##新規投稿の時に性別を選択できるようにする

① enumを使用する時のデータ型は gender:integer にする

② enum gender: { man: 0, woman: 1 } をモデルに記述

③ view 作成

 <%= f.label :man %>
 <%= f.radio_button :gender, :man %>
 <%= f.label :woman %>
 <%= f.radio_button :gender, :woman %>

完成:blush:

なんだけど、これだと viewでは man か woman と出でしまうので、

私は
enum gender: { 男: 0, 女: 1 }

 <%= f.label :男 %>
 <%= f.radio_button :gender, :男 %>
 <%= f.label :女 %>
 <%= f.radio_button :gender, :女 %>

という風にしました。
いいのかわかんないけど:sweat:

英語を日本語にするgemを使った方かいいのかな??

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?