[RUBY] Enum misconfiguration. For some reason, I can't get data from the column specified by Enum ...

Occurrence background </ font>

  • Record as a memorandum (it's a shame in terms of material ...) Data cannot be retrieved when Enum is set in the following model.

table.rb


class ColorManage < ApplicationRecord
  enum color_type: { single: 0, double: 1, graphic: 2 }
(abridgement)

(Premise) When you press the radio button called single, 0 is input.

erb:color-edit.html.erb


  <!--Color type, which setting to use.-->
  <%= color_manage_record.radio_button :color_type, :single ,class:"color-form__button" %>
  <%= color_manage_record.label :color_type, "single-color", {class: "color-form__tag"} %>

Problem> As shown in the image, color_type is entered as "zero", but when I try to extract the model and get the column value, it returns null </ font>

image.png

environment </ font>

item Contents
OS.Catalina v10.15.4
Ruby v2.5.1
Ruby On Rails v5.2.4.3
MySQL V5.6

Correspondence procedure </ font>

Cause) The definition of the table was string, so I redefined the enum as follows. It's a portfolio, so I'm ashamed to change the design side.

test.rb


  enum color_type: { single: "single", double: "double", graphic: "graphic" }

This solved it.

that's all.