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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:23:11+00:00 2026-05-21T19:23:11+00:00

I have fields hr and min , both integers in my application. For hr

  • 0

I have fields hr and min, both integers in my application. For hr field, if the user enters “1” I would like Rails to automatically pad it to “01” before saving it to the database. Also for the min field if the user enter “0” it should put in as “00”.

How can I do this?

  • 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-21T19:23:12+00:00Added an answer on May 21, 2026 at 7:23 pm

    It’d be better to store it as an integer and just display it as you described on runtime. Every language has its own way to pad zeros – for Ruby you can use String#rjust. This method pads a string (right-justified) so that it becomes a given length, using a given padding character.

    str.rjust(integer, padstr=' ') → new_str

    If integer is greater than the length of str, returns a new String of length integer with str right justified and padded with padstr; otherwise, returns str.

    some_int = 5
    some_int.to_s.rjust(2, '0')  # => '05'
    some_int.to_s.rjust(5, '0')  # => '00005'
    
    another_int = 150
    another_int.to_s.rjust(2, '0') # => '150'
    another_int.to_s.rjust(3, '0') # => '150'
    another_int.to_s.rjust(5, '0') # => '00150'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a search form with min and max fields. It queries a MySQL
I have fields in the column that look like so: 2/8B, 3, 3/8B, 4/8B,
I want to make a user-registration form where I will have fields such first
I have two tables: TableA and TableB. Both have dates and rates fields. I
all. I would like to ask if it is possible to have multiple forms
I have table medicine record with fields Name qunty min expiry a 2 3
I have this MySQL query that I'd like to optimize: SELECT min(`topic_id`) FROM `gallery_topics`
I have a table with two fields - a field for "date" entered as
I have some documents in couchdb that have fields that are arrays of id's
In my database we have fields where the data is not readable. I now

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.