Reputation: 334
I have model,
class Test < ActiveRecord::Base
as_enum :test, [:test, :test_1, :test_1_2]
end
I need to create a f.select
dropdown with enum
. But I am facing an issue preparing dropdown with enum
.
Here is my code:
<%= f.select :test, options_for_select(Test.tests.keys.to_a), {}, :class => "form-control" %>
But prepared a wrong select box.
Can anyone have any suggestion?
Upvotes: 0
Views: 281
Reputation: 1161
Use the code below. Titleize function capitalizes all the words and replaces the underscores with spaces. You can read more about it here
<%= f.select :test, Test.tests.keys.map {|test| [test.to_s.titleize, test]}, {}, :class => "form-control" %>
Upvotes: 2