我在十进制类型列中将价格字符串保存到我的数据库中。
价格是这样的"$ 123.99",这很好,因为我写了一些代码来删除"$ ".
但是,我忘记了价格可能包含逗号,因此"$ 1,234.99"破坏了我的代码。我怎样才能删除逗号?
这是我删除美元符号和空格的代码:
def price=(price_str)
  write_attribute(:price, price_str.sub("$ ", ""))
  # possible code to remove comma also?
end