I declare a model with a type enumlike:
class Event < ActiveRecord::Base
enum event_type: { "special_event" => 0,
"pto" => 1,
"hospitality" => 2,
"classroom" => 3
}
Then, in my update view, I have a form with:
<%= simple_form_for @event do |f| %>
<%= f.input :event_type, collection: Event.event_types.keys %>
...
<% end %>
This works fine, and I get a selection filled with my enumerated types. When I execute @event.update(event_params)in my controller, I can check the db and see that the field has event_typebeen updated to the correct integer value.
However, when I revise the edit page, the selection shows nil. If I check its value by adding a debug line to my form:
<%= f.input :event_type, collection: Event.event_types.keys %>
<%= debug @event %>
I see that the value for is event_typetrue:
--- !ruby/object:Event
attributes:
...
event_type: '2'
but the input selector is still empty, and does not show the "hospitality" as it should.
Any ideas would be much appreciated. :)