In Rails, how do I map a millisecond field to hours, minutes, and seconds fields?
<p>I’m using Rails 4.2.3.  In my model, I have a field that records the amount of time it took someone to do something.  It is a field called “time_in_ms,” which is an integer in my PostGresql database.  My question is, in my form, I don’t want the user to have to enter in milliseconds, I would rather have them select from hours, minutes, and seconds.  How do I set this up in my Rails form?  Since there are no such fields in my model, I don’t know what to put in my “collection_select” attributes … </p>

<pre><code>  &lt;div class="field"&gt;
    &lt;%= f.label "Time" %&gt;
    &lt;%= collection_select(:time_unit, :time_unit, @hours, {:prompt =&gt; true} ) %&gt; hrs
    &lt;%= collection_select(:time_unit, :time_unit, @minutes, {:prompt =&gt; true} ) %&gt; min
    &lt;%= collection_select(:time_unit, :time_unit, @seconds, {:prompt =&gt; true} ) %&gt; sec
    &lt;%= f.hidden_field :time_in_ms, :validate =&gt; true %&gt;
  &lt;/div&gt;
</code></pre>

<p>How do I properly write and pre-populate the selectors based on my single “time_in_ms” field in my model?</p>

<p>Thanks, - Dave</p>