Number input field (stuck with whitespaces)

All,

I am RoR newbee, so maybe this is stupid question, but I can’t figure
it out. I have a form from which I want to get some numbers. But if
user has typed a number with whitespaces in it, I am getting only the
first part until the whitespace.

For example, if user types 300 000, the record is saved as only 300.

Can anybody help?

There’s probably a better way to do this but here is one suggestion.
Instead of putting the return from the form into the (I presume
numerical) model method, create a dummy method which gets the input from
the form and puts it into a string. Then convert it yourself to a
number.

number = string_from_form.gsub(/\s+/, “”).to_i

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs