\u305d\u308c\u305e\u308c\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u309210, 20, 30, 40\u3068\u3044\u3046\u6570\u5024\u3067\u7ba1\u7406\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002
\u305d\u306e\u3068\u304d\u5358\u306binteger\u578b\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u3059\u308b\u3068\u3001\u4f8b\u3048\u3070\u3001\u767a\u58f2\u4e2d\u306b\u30b9\u30c6\u30fc\u30bf\u30b9\u3092\u30d5\u30a9\u30fc\u30e0\u306f<\/p>\n\n\n\n
<%= form_for @product do |f| %>\n <%= f.label :status %>\n <%= f.radio_button :status, 10 %> \u767a\u58f2\u4e88\u5b9a\n <%= f.radio_button :status, 20 %> \u767a\u58f2\u4e2d\n <%= f.radio_button :status, 30 %> \u7d76\u7248\n <%= f.radio_button :status, 40 %> \u518d\u8ca9\u672a\u5b9a\n<% end %><\/code><\/pre><\/div>\n\n\n\n\u3068\u306a\u3063\u305f\u308a\u3001<\/p>\n\n\n\n
def in_sale?\n self.status == 20\nend<\/code><\/pre><\/div>\n\n\n\n\u3068\u306a\u308b\u306a\u3069\u3001\u3053\u3053\u3060\u3051\u3067\u306f\u610f\u5473\u304c\u5206\u304b\u3089\u306a\u3044\u6570\u5024\u304c\u5165\u3063\u3066\u53ef\u8aad\u6027\u304c\u60aa\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002
\u305d\u308c\u3092\u9632\u3050\u305f\u3081\u306e\u6a5f\u80fd\u3068\u3057\u3066Rails\u306eModel\u306b\u306fEnum\u3068\u3044\u3046\u6a5f\u80fd\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n
<\/span>Enum\u306e\u4f7f\u3044\u65b9<\/span><\/h2>\n\n\n\nModel\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u307e\u3059\u3002<\/p>\n\n\n\n
class Product < ActiveRecord::Base\n enum status: {will_be_released: 10 ,in_sale: 20, sold_out: 30, resale_undecided: 40}\nend<\/code><\/pre><\/div>\n\n\n\n\u3053\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3057\u3066\u3084\u308b\u3068\u3001DB\u306e\u5024\u306f10,20,30,40\u306e\u307e\u307e\u3067\u3001\u30b3\u30fc\u30c9\u5185\u3067\u306f:will_be_released<\/code>\u306a\u3069\u3067\u53c2\u7167\u3067\u304d\u307e\u3059\u3002
\u305f\u3068\u3048\u3070\u3001\u5148\u307b\u3069\u306eView\u306e\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<%= form_for @product do |f| %>\n <%= f.label :status %>\n <%= f.radio_button :status, :will_be_released %> \u767a\u58f2\u4e88\u5b9a\n <%= f.radio_button :status, :in_sale %> \u767a\u58f2\u4e2d\n <%= f.radio_button :status, :sold_out %> \u7d76\u7248\n <%= f.radio_button :status, :resale_undecided %> \u518d\u8ca9\u672a\u5b9a\n<% end %><\/code><\/pre><\/div>\n\n\n\n\u3053\u306e\u3088\u3046\u306b\u3057\u3066\u3084\u308c\u3070\u3001\u7121\u610f\u5473\u306a\u6570\u5024\u304c\u30b3\u30fc\u30c9\u306b\u5165\u3089\u306a\u3044\u306e\u3067\u3088\u307f\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002
\u307e\u305f\u3001\u3075\u305f\u3064\u76ee\u306ein_sale?<\/code>\u30e1\u30bd\u30c3\u30c9\u306b\u3064\u3044\u3066\u3067\u3059\u304c\u3001\u5b9f\u306feunm\u3092\u5b9a\u7fa9\u3057\u305f\u6642\u70b9\u3067\u81ea\u52d5\u7684\u306b\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002\u540c\u69d8\u306bstatus<\/code>\u3092:in_sale<\/code>\u306b\u66f4\u65b0\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3068\u3057\u3066in_sale!<\/code>\u3082\u4f5c\u6210\u3055\u308c\u3066\u3044\u307e\u3059\u3002
\u307e\u305f\u3001:will_be_released<\/code>, :in_sale<\/code>, :sold_out<\/code>, :resale_undecided<\/code>\u4ee5\u5916\u306e\u5024\u3092\u4ee3\u5165\u3059\u308b\u3068\u3001\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u305f\u3081\u3001DB\u81ea\u4f53\u306bConstraint\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u306a\u304f\u3001\u30c7\u30fc\u30bf\u306e\u6574\u5408\u6027\u3082\u4fdd\u3064\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<\/span>\u88dc\u907a<\/span><\/h2>\n\n\n\n\u4eca\u56de\u3001\u305d\u308c\u305e\u308c\u306e\u5224\u5225\u7528\u306e\u6570\u5b57\u309210, 20, 30, 40\u3068\u3057\u307e\u3057\u305f\u304c\u3001\u3053\u306e\u3088\u3046\u306b10\u98db\u3073\u306b\u3001\u3042\u308b\u3044\u306f100\u98db\u3073\u306b\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001\u9593\u306b\u65b0\u3057\u3044\u30b9\u30c6\u30fc\u30bf\u30b9\u304c\u3067\u304d\u305f\u3068\u304d\u300115\u306e\u3088\u3046\u306b\u9593\u306b\u5024\u3092\u6570\u5024\u5165\u308c\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n
\u305f\u3060\u306eID\u3068\u3057\u3066\u306e\u5f79\u5272\u3057\u304b\u679c\u305f\u3057\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u3082\u3061\u308d\u3093\u3001\u5f8c\u308d\u306b50\u3068\u304a\u3044\u3066\u3082\u3044\u3044\u306e\u3067\u3059\u304c\u3001\u306a\u3093\u3068\u306a\u304f\u6c17\u6301\u3061\u60aa\u3055\u304c\u3042\u308b\u306e\u3067\u3001\u81ea\u5206\u306f\u3044\u3064\u3082\u3053\u306e\u3088\u3046\u306b\u7f6e\u3044\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n
<\/span>\u307e\u3068\u3081<\/span><\/h2>\n\n\n\nModel\u306eEnum\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u5f97\u3089\u308c\u308b\u4e3b\u306a\u30e1\u30ea\u30c3\u30c8\u306f\u53ef\u8aad\u6027\u306e\u5de5\u5834\u3067\u3059\u304c\u3001\u69d8\u3005\u306a\u4fbf\u5229\u306a\u30e1\u30bd\u30c3\u30c9\u304c\u7528\u610f\u3055\u308c\u305f\u308a\u3001DB\u306e\u8a2d\u5b9a\u3092\u5909\u66f4\u3057\u306a\u304f\u3066\u3082\u4fdd\u5b58\u53ef\u80fd\u306a\u5024\u3092\u5897\u3084\u305b\u305f\u308a\u3057\u307e\u3059\u3002
\n\u307e\u305f\u3001enum_help<\/code>\u3068\u3044\u3046Gem\u3092\u4ee3\u5165\u3059\u308b\u3053\u3068\u3067\u591a\u8a00\u8a9e\u5bfe\u5fdc\u3082\u53ef\u80fd\u3067\u3059\u3002
\n\u3053\u306e\u3088\u3046\u306a\u4fdd\u5b58\u3059\u308b\u5024\u304c\u6c7a\u307e\u3063\u3066\u3044\u308b\u3082\u306e\u306b\u95a2\u3057\u3066\u306f\u7a4d\u6975\u7684\u306bEnum\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u30b7\u30b9\u30c6\u30e0\u3092\u69cb\u7bc9\u3057\u3066\u308b\u3068\u3001\u5e7e\u3064\u304b\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u3092\u6301\u3064\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u5546\u54c1\u306b\u3064\u3044\u3066\u306e\u30e2\u30c7\u30ebProduct\u306estatus\u3068\u3057\u3066\u3001\u300c\u767a\u58f2\u4e88\u5b9a\u300d\u300c\u767a\u58f2\u4e2d\u300d\u300c\u7d76\u7248\u300d\u300c\u518d\u8ca9\u672a\u5b9a\u300d\u306e4\u3064\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u3092\u6301\u3063\u3066\u3044\u308b\u3068\u3057\u307e\u3059\u3002 \u3053\u308c\u3089\u3092 […]<\/p>\n","protected":false},"author":1,"featured_media":208339,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5,53],"tags":[141,46,142,140,50],"class_list":["post-4095","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-program","category-ruby","tag-enum","tag-for-beginner","tag-model","tag-rails","tag-ruby"],"aioseo_notices":[],"jetpack_featured_media_url":"http:\/\/cms.inter-arteq.com\/wp-content\/uploads\/2022\/03\/use_enum_for_enumerate_values_on_rails.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/posts\/4095"}],"collection":[{"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/comments?post=4095"}],"version-history":[{"count":8,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/posts\/4095\/revisions"}],"predecessor-version":[{"id":208376,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/posts\/4095\/revisions\/208376"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/media\/208339"}],"wp:attachment":[{"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/media?parent=4095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/categories?post=4095"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cms.inter-arteq.com\/wp-json\/wp\/v2\/tags?post=4095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}