🖥
How to get the id before overwriting the value with Rails | enums
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
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
公開日時
2019-04-16
Discussion