LoginSignup
0
0

More than 3 years have passed since last update.

enumを日本語化して、連動したラジオボタンを生成する方法

Last updated at Posted at 2020-07-11

やりたいこと

以下のようなenumをラジオボタンで表現したい。

enum loadtype: { normal: 0, trail: 1, beach: 2, track: 3 }

かつ、選択肢は日本語で出るようにしたい。

enumの日本語化について

こちらの記事の内容に従って日本語化します。
https://qiita.com/tanutanu/items/d44a92425188a4489ec6

日本語化したenumに連動したラジオボタンを記述

ViewのFormで以下のように記載

<%= f.collection_radio_buttons :loadtype, Post.loadtypes_i18n, :first, :last  %>

コードの意味は以下の通り

<%= f.collection_radio_buttons [column名], [表示対象のコレクション], [value], [textに表示する文字列]  %>
0
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
0
0