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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:06:29+00:00 2026-05-25T16:06:29+00:00

My form has the following: <%= f.select(:amount, Order::AMOUNT_VALUES, {:blank => false}) %> My model

  • 0

My form has the following:

<%= f.select(:amount, Order::AMOUNT_VALUES, {:blank => false}) %> 

My model has:

  AMOUNT_VALUES = { '$ 0.50' => 0.5, '$ 1' => 1, '$ 2' => 2, '$ 5' => 5, '$ 10' => 10 }
  validate :amount_values_to_be_of_certain_values

  def amount_values_to_be_of_certain_values
    puts self.amount
    unless AMOUNT_VALUES.has_value? self.amount
      errors.add(:amount, 'not a valid field')
    end
  end

If I select 0.5 and submit the form. The form complains saying “Amount not a valid field”. If I select one of the other values, the form submits fine.

It seems the problem is with a decimal point that starts with 0.

What is wrong here?

  • 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-25T16:06:30+00:00Added an answer on May 25, 2026 at 4:06 pm

    If you’re storing amount in an integer field, then it’s going to round any floating point numbers you put into it down. That’s why self.amount.to_f is 0.0, because putting 0.5 into an integer field changes it to 0, and 0.to_f is 0.0.

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

Sidebar

Related Questions

I have a form that has select inputs as well as checkboxes. The following
The mailing list form I am creating has the following fields: first name, last
I am generating a simple form with php. The following code has been reduced
My android application has several warnings of the following form when I run it
My form has a custom element like below, created using custom ajax: <select jwcid=testtest
I have created the following select using the option_groups_from_collection_for_select form helper in Rails as
I have a query of the following form: SELECT * FROM MyTable WHERE Timestamp
I have a simple PHP script with a form that has two select fields,
I have model called Product and it has the following columns: create_table :products do
I have the following form that has 2 selects: <form id=form class=form_visitar method=post action=ajax/selects.php>

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.