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 212765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:13:00+00:00 2026-05-11T18:13:00+00:00

Background, Part 1 I have a form that collects both frequency and duration from

  • 0

Background, Part 1 I have a form that collects both frequency and duration from the user. We set both the frequency and the duration in seconds, but, to the user, they are always presented as days or weeks. For example, the user sees “every other day”, but the value set on the option is ‘172800’ as that is the number of seconds in 2 days.

Background, Part 2 I’m working on an app that we want the user to have an invite code in order to be able to use. So, as part of signing up, the user has to enter an invite code that is connected to a specific email address.

Background, Part 3 I’m a newbie to RoR and am working on someone else’s code. I’m about 10 chapters into the 3rd edition of “Agile Web Development with Rails”. The person that wrote this isn’t available for me to ask them questions until sometime next week and I’d like to solve this before then. If I don’t get a resolution before then, I’ll post the answer back here once I get it.

Problem When the user submits the form with everything matching except for the invite code and email address, the form returns and the frequency and duration are not re-populated. Now, I know why this is happening. I just don’t know how to fix it. Let’s dig in to some code, shall we?

Here’s the RoR code to create the duration and frequency select form fields:

<%= frequency_select c, :frequency %> 
<%= duration_select c, :duration %>

Here’s the details on “frequency_select”

def frequency_select(f, method)
    options = [["day", 1.day], ["other day", 2.days], ["week", 1.week]]
    f.select method, options, :include_blank => true
end

Here’re the details on “duration_select”

def duration_select(f, method, unit="day" )
    values, units = *case unit
        when "day" : [[[5, 5], [15, 15], [30, 29]], "days"]
        when "other day" : [[[15, 15], [30, 29], [45,45]], "days"]
        when "week" : [[[4, 29], [6, 43], [8, 57]], "weeks"]
    end
    f.select method, values.map {|(label, i)| ["#{label} #{units}", i.days]}, :include_blank => true
end

Now, the fun part. Here’s the code for “:frequency”

def frequency(unit=:days)
    seconds = super
    convert_seconds_to_units(seconds, unit)
end

(Wait for it.)

And here’s the code for “:duration”

def duration(unit=:days)
    seconds = super
    convert_seconds_to_units(seconds, unit)
end

The reason the duration and frequency fields aren’t re-populating is because the check to match the invite code and email address is happening after the frequency and duration are converted to days.

See, if the form has other errors in addition to the email and invite code not matching, the conversion from seconds to days doesn’t happen. But, if everything else checks out, the conversion happens and then the invite code and email address are compared. If there’s an error, the data goes back to the browser, but the duration and frequency values are now in days and do not match the values (in seconds) of the duration and frequency in the HTML form.

So, my question is — and I imagine it’s complete newbie question — how do you hold off on converting the frequency and duration values until after the invite code and email address have been matched.

Lemme know if you need to see more code. I tried to provide everything you would need without overwhelming you. Though, if I missed anything just let me know.

Thanks!
Rick

  • 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-11T18:13:00+00:00Added an answer on May 11, 2026 at 6:13 pm

    I could not find a suitable solution to this. The main issue is just that I shouldn’t be converting seconds to days — I should just be using days.

    The problem with tomafro’s solution is that I would need 2 scripts to generate options for the duration and frequency select options, which is doable, but all this extra code begs the question: why do I need the conversion in the first place? And I’m not sure that I do. I’ll be looking into this further to see if changing it creates unforeseen bugs.

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

Sidebar

Related Questions

As part of a VBA program, I have to set the background colors of
This is probably a multi-part question. Background: we have a native (c++) library that
Background: I have a set of java background workers I start as part of
Basically what i have is a vb.net form that when a user clicks the
I have an app that, when a color scheme is selected from a form
I have some code that uses a multi-part form and HTML5 file object to
I have a div with 60% opacity, to show part of a background image
I'm having trouble with a gradient drawing call. I have a Form that looks
i have one div that contain three div for a part in my website
Background I'm writing an part of my app that has no UI. It sits

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.