“You can get the integer values for an enum from the class the enum is on: Model.sale_infos # Pluralized version of the enum attribute name That returns a hash like: { "plan_1" => 1, "plan_2" => 2 ... } You can then use the sale_info value from an instance of the Model class to access the integer

kent-where-the-light-iskent-where-the-light-is のブックマーク 2016/10/17 11:20

その他

このブックマークにはスターがありません。
最初のスターをつけてみよう!

How get integer value from a enum in Rails?

    I have a enum in my Model that corresponds to column in the database. The enum looks like: enum sale_info: { plan_1: 1, plan_2: 2, plan_3: 3, plan_4: 4, plan_5: 5 } How can I get the integer value?...

    \ コメントが サクサク読める アプリです /

    • App Storeからダウンロード
    • Google Playで手に入れよう