🖥

How to get the id before overwriting the value with Rails | enums

2019/04/16に公開

Solution

Not a method. Use a hash.

 person[:gender] # => 0 

problem

For example, if there is such a model.

 class Person < ActiveRecord::Base enum gender: { male: 0, female: 1 } end 

Because enum rewrites the original method. The original value of 0 or 1 can not be taken.

 person = Person.first person.gender # => "male" 

The solution is at the beginning.

environment

  • Rails 4.2.5

Original by

Rails | enums で 値を上書きする前の id を得る方法

About

About this translattion

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2019-04-16

Discussion