Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8197451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:44:40+00:00 2026-06-07T05:44:40+00:00

I have a Rails 3 application with a prescription model. The model has a

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:44:41+00:00Added an answer on June 7, 2026 at 5:44 am

    I’ll provide an example of how you’d use the chronic gem, since it seems tailor-made for this purpose:

    require 'chronic'
    duration = "3 months" # => "3 months" 
    Time.now # => 2012-07-09 18:43:50 -0700 
    Chronic.parse(duration + " from now") # => 2012-10-09 18:43:55 -0700 
    

    If I understand your use case correctly, you can then just get rid of the datetime select entirely. Ask the user for the text duration and assign that to the text attribute. Then use chronic to determine the time value from the text parameter and assign that to the datetime attribute. For extra credit get the parsed time value asynchronously and display it on the page before they submit the form so they can see that what they are submitting makes sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails application, I have the following DB schema: each User has
I have a rails application where each user has a separate database. (taking Joel
I have a rails application that has three different types of users and I
I have two rails application running at different ports. First at 3000 and the
I have a Rails application that has to co-exist with a very old legacy
I have a Rails application where the user can insert text with a WYSIWYG-Editor.
I have a Rails application that has file uploading. Once the file is uploaded
I have a Rails application that unfortunately after a request to a controller, has
I have a rails application and I want to display messages (Message) to the
I have a rails application in which a user creates a record called a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.