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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:44:22+00:00 2026-06-17T19:44:22+00:00

I’m a beginner to ruby and ruby on rails, and I’m attempting to create

  • 0

I’m a beginner to ruby and ruby on rails, and I’m attempting to create a complex form using simple_form. Everything is working already, but I wanted to customize the “time” field in a very specific way.

When I use:

<%= f.input :hour %>

It renders two select fields, being the “hour” field populated with options from 00 to 23, and the “minute” field populated with options from 00 to 59.

But that’s not what I want. I want to replace the use of two select fields for the time with a single select field with custom pre-populated options, with time ranging from 8am until 22pm, in 15 minutes increments, and also have the text for the options show times with the syntax “8h00”, “8h15”, “8h30”, “8h45”, “9h00”, “18h00”, “18h15”, “18h30”, “18h45”, etc.. being “21h45” the last option available.

I have managed to customize it a bit more using these options:

<%= f.input :hour, :as => :time, :minute_step => 15 %>

Although that solves the 15 minute increment problem, it still renders two select fields.

This would be the html equivalent of what I wanted to have simple_form render for me:

<select name="hour">
<option value="08:00:00">08h00</option>
<option value="08:15:00">08h15</option>
<option value="08:30:00">08h30</option>
<option value="08:45:00">08h45</option>
...
<option value="21:30:00">21h30</option>
<option value="21:45:00">21h45</option>
</select>

I’m pretty sure this is very easy to implement using a collection that loops from 8..21 and then loops again with ’00’, ’15’, ’30’ and ’45’, and then outputs options in the syntax that I want (hour + “h” + minute).

I want to create a custom “date” field, because there will many date fields in a single form (for a “appointment” related application that I’m creating), but since I’m a beginner on ruby on rails, I’m really lost on what would be the most smart way to implement this. I’m not sure if I should implement a custom field in simple_form, if I should use a helper function, or what.

  • 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-17T19:44:23+00:00Added an answer on June 17, 2026 at 7:44 pm

    With help from Carlos Antonio da Silva, from simpleform’s mailing list, we’ve fixed this by creating a custom input like this:

    app/inputs/hour_input.rb

    class HourInput < SimpleForm::Inputs::Base
      def input
        @builder.select(attribute_name, hour_options, { :selected => selected_value }, { :class => "input-medium" })
      end
    
      private
    
      # The "Selecione..." string could also be translated with something like: I18n.t("helpers.select.prompt')
      def hour_options
        hour = [['Selecione...', '00:00:00']]
        (8..21).each do |h|
          %w(00 15 30 45).each do |m|
            hour.push ["#{h}h#{m}", "#{"%02d" % h}:#{m}:00"]
          end
        end
        hour
      end
    
      def selected_value
        value = object.send(attribute_name)
        value && value.strftime("%H:%M:%S")
      end
    end
    

    and then <%= f.input :hora, :as => :hour %> in the view.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am using JSon response to parse title,date content and thumbnail images and place
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

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.