Select enum from form to set role

前端 未结 5 1357
醉酒成梦
醉酒成梦 2021-02-01 22:38

Ruby on Rails 4.1

I am using Devise with enum role. It currently sets a defualt role when the User is created. I want to add a field to the form that creates Users to se

5条回答
  •  遥遥无期
    2021-02-01 23:10

    The cleanest way that I've come with in order to use collection_select with enums is the following:

    f.collection_select :diet_preference, User.roles.map{ |dp| [dp.first, dp.first.humanize] }, :first, :second
    

提交回复
热议问题