4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/ar_strip_commas.rb', line 4
def self.strip_commas_from(*columns)
unless (self.respond_to?(:write_attribute_without_strip_commas))
class_eval do
def write_attribute_with_strip_commas(f, v)
if (self.class.strip_commas_fields.include?(f.to_sym) && v.is_a?(String))
write_attribute_without_strip_commas(f, v.gsub(",", ""))
else
write_attribute_without_strip_commas(f, v)
end
end
alias_method_chain :write_attribute, :strip_commas
cattr_accessor :strip_commas_fields
self.strip_commas_fields = []
end
end
columns.each do |column|
self.strip_commas_fields << column.to_sym
end
end
|