I have a requirement to store values in a database as unitless decimals(12,9) which will be presumed to be metric values. For display/editing purposes I need the user to be able to choose their input method – no mixing and matching on a form, just a simple User#current_units call to determine the expected units.
When User#current_units is “mm” all of my form fields are straight forward…
My issue is when a current_units is “in”, what’s a good method for doing all the translation? The text_field for diameter should read “5.9055”. If a user altered it to read “6” then it should save back to the db as “152.400000000”
I’ve tried everything from the ruby-units gem to composed_of (which is practically useless with rails 4 getting rid of it). storing the units in the db is a no go only because I need to be able to search for “items where diameter > x and diameter < y”
If anyone has any theories on a good starting point I’d love to elaborate further on what I’ve tried and failed with.