Search code examples
ruby-on-railsrubyactiveadminformtastic

How to map a list of strings to an integer attribute in Ruby on Rails using Formtastic syntax?


In my ActiveAdmin application, I have a Country model which has an integer attribute schedule with limited range of values from 0 to 4.

In new and edit action forms, I would like to select a string from a drop-down box and map it to a corresponding integer value rather than entering the integer value itself directly.

How could I do that using the Formtastic gem syntax?


Solution

  • See doc about SelectInput here. I think it looks like:

    <%= f.input :schedule, :as => :select, :collection => 1..4 %>