I have a requirement to display duration as HH:MM in Rails as two select boxes one for hours and other for minutes. Restrict the hours to max of 4:00. ‘duration'(column type:integer) is stored as minutes in database.
And I am using formtastic.
If I dispaly input as time, I am able to get the output format as drop down HH:MM.
“<%= f.input :duration, :label => ‘Duration’, :as=>:time, :minute_step => 15, :hint=>”Measured in hours”, :end => 10 %>”
How do I restrict the hours shown for selection( only 01, 02, 03, 04 should be displayed in the drop down for hours)?
Please let me know if there are any options to be specified for Rails/Formtastic. Or is there any better way to handle this scenario?
I don’t see any options to limit it through Formtastic. You could just display the input as a select and pass it the options you want explicitly.
Then you’ll probably need to add these virtual attributes in the model:
And you might want to look at this answer to get them to look more like the original.
There might be some clever, quicker way to do this, but this is the first thing that comes to mind.