Skip to content

Instantly share code, notes, and snippets.

@henrik
Created October 26, 2009 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrik/3d99d172175ee3bc64a1 to your computer and use it in GitHub Desktop.
Save henrik/3d99d172175ee3bc64a1 to your computer and use it in GitHub Desktop.
Make Active Record not cut off at the first space when assigning numbers.
# Foo.some_number = "123 456" should set 123456, not 123.
class ActiveRecord::Base
def convert_number_column_value_with_space_removal(value)
convert_number_column_value_without_space_removal(value.is_a?(String) ? value.gsub(/\s/, '') : value)
end
alias_method_chain :convert_number_column_value, :space_removal
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment