0

I am trying to drop in enum values setup with the 'Enumerize' gem into the radio collection select field on a rails-bootstrap-form.

An example is shown how to do this with an ActiveRecord collection. How should I modify the example

<%= f.collection_radio_buttons :skill_level, Skill.all, :id, :name %>

So that it can accept an enum that is setup on my model

<%= f.collection_radio_buttons :level %>

skill.rb

class Skill < ActiveRecord::Base
  extend Enumerize
  enumerize :level, in: [:good, :ok, :bad ]
end

The Enumerize documentation says

SimpleForm

If you are using SimpleForm gem you don't need to specify input type (:select by default) and collection:

<%= simple_form_for @user do |f| %>

  <%= f.input :sex %>

<% end %>

and if you want it as radio buttons:

<%= simple_form_for @user do |f| %>

  <%= f.input :sex, :as => :radio_buttons %>

 <% end %>
Rob Wise
  • 4,930
  • 3
  • 26
  • 31
Jay Killeen
  • 2,832
  • 6
  • 39
  • 66

1 Answers1

0

If you're using simple-form, then the documentation says all you need to do is this:

<%= simple_form_for @skill do |f| %>

  <%= f.input :level %>

<% end %>

If you're using rails-bootstrap-form, the documentation shows how to use collection_radio_buttons with Rails's built-in enum functionality, which you aren't using. So I believe you would need to pass in the Skill.level.options call as the collection values, but the :level method for (as the method, value_method, and text_method arguments):

<%= bootstrap_form_for @skill do |f| %>

  <%= f.collection_radio_buttons :level, Skill.level.options, :level, :level %>

<% end %>
Rob Wise
  • 4,930
  • 3
  • 26
  • 31