0.0
No commit activity in last 3 years
No release in over 3 years
An ActiveRecord extension for properly parsing strings with commas as input to numeric columns.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.0.0
~> 1.5.2
 Project Readme

ar_strip_commas

This gem adds a class method to ActiveRecord::Base for automatically handling the conversion of strings with commas ("1,203") to the intended value on numeric columns.

self.strip_commas_from_all_numbers

Remove commas from all numeric columns. e.g.

class Widget < ActiveRecord::Base
  strip_commas_from_all_numbers
end
widget = Widget.new(:price => "1,200", :weight => "1,872.0")
widget.price == 1200     # true
widget.weight == 1872.0  # true

Installation

Add this line to your application's Gemfile:

gem 'ar_strip_commas'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ar_strip_commas

The right way?

I'm surprised I couldn't find anything built into rails for handling this. If someone knows the "right way" to handle this, send me an email and I'll replace this project with a readme describing it.