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

  • Home
  • SEARCH
  • 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 3224136
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:11:16+00:00 2026-05-17T16:11:16+00:00

I have a form which i’d like to simplify. I’m recording a startdate and

  • 0

I have a form which i’d like to simplify. I’m recording a startdate and an enddate, but would like to show the user only a startdate and then a drop down with number of days.

But I’m having problems with my model and storing it correctly.

The first part works.

  def date=(thedate)
     #puts the startdate in the correct format...
     self.startdate = Date.strptime(thedate, '%m/%d/%Y')
  end

The problem I have has to do with the fact that the end date is based on the startdate + the no_days which is itself a virtual attribute. I tried doing the second part as a after_validation callback but it doesn’t seem to work.

  def set_dates
    if self.startdate
      self.enddate = self.startdate + days
    end  
  end
  • 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-05-17T16:11:17+00:00Added an answer on May 17, 2026 at 4:11 pm

    First of all, why do you need to convert a date attribute in your startdate? Why don’t you use something like f.date_select :startdate in you form?

    Then, in your model you need something like attr_accessor :number_of_days with wich you can get the number_of_days as an integer in your form with f.select :number_of_days, (1..10).to_a (set the array as you like).

    You can set your callback the following way:

    after_validation :set_enddate
    
    def set_enddate
      if self.startdate
        self.enddate = self.startdate + self.number_of_days.days
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTML form which must be posted to a URL. I would
I have a form which submits user first and last name using POST signin.html
I have a form which takes in data, but it is not stored in
I have a form which has about 40 fields.What are the effective patterns to
I have a form which escaped the input in PHP in a pretty standard
I have a form which shows a graph which was made in Microsoft Chart
i have a Form which has a button, on the button click event, a
I have a form which submits to a Servlet from which the Servlet responds
I have a form which has a textbox with the name attribute username and
I have a form which contains couple fields. Its very easy to validate this

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.