How to Properly Configure Rails 4.1 Enums in ActiveAdmin

后端 未结 3 672
日久生厌
日久生厌 2021-02-02 07:48

I\'ve got a Rails 4.1 app in which I use an enum to represent the privacy level of an object.

In my schema:

t.integer \"privacy_level\", default: 0
         


        
3条回答
  •  失恋的感觉
    2021-02-02 08:15

    In order to use enums in ActiveAdmin's filters use:

    filter :level, as: :select, collection: Model.levels
    

    assuming an enum attribute named level

    This will make sure to actually put the integer value in the query and not the key name.

提交回复
热议问题