I am working on a form that has a select list:
<%= f.select :type, options_for_select(Property.types), {prompt: "Select Type of Property..."}, class: "form-control" %>
type
is an integer in my database. The Property.types
is pulling the list from an enum
attribute in my Property model:
enum type: { Type_1: 1, Type_2: 2, Type_3: 3 }
For some reason, when submitting the form, I am getting an error:
ArgumentError ('1' is not a valid type): Completed 500 Internal Server Error in 10ms (ActiveRecord: 4.0ms)
I assume that is because the selected list value is being submitted as a string instead of an integer.
I am using Rails v.5.2.1.
How to solve that issue?
<%= f.select :type, Property.types.map { |key, value| [key.humanize, key] }, {prompt: "Select Type of Property..."}, class: "form-control" %>
– Marcela