I have a Rails 3 application with a prescription model. The model has a number of fields, two of them are to calculate and display the duration of a prescription.
At the moment the user enters a value in a text field such as '3 Months' and then manually changes a datetime input to three months from now. This seems like a perfect form to automate for the user.
Currently the fields are like this:
Duration of Treatment
<%= f.text_field :duration, :class => "input-text" %>
Date of Expiry
<%= f.datetime_select :expiry, :order => [:day, :month, :year], :class => "input-text" %>
So, my question. How can I create two dropdown lists for the duration field such as:
[1] [Day]
The user can select the number from the first list and in the second they can choose Day, Week or Month.
The value they pick using the duration select boxes would be saved as a text string e.g. "1 month" and the value of the Time.now in 1 month would be saved as a datetime value in the expiry column.
Is something like this possible to do? If so, how?