Plugins - acts_as_currency

StarAdd to favorites

There's a problem in ActiveRecord. Let's say you have a field in a table that's supposed to be money, for example:

add_column :products, :price, :decimal

and you have an entry form on your website for admins to add products. Without even thinking, they will likely type the price with a dollar sign ('$'). If you follow the principal of least surprise, you will need to support this scenario. However, since ActiveRecord interprets the type as a decimal (since that's how it is in the database), you will get a silent fail in which all of your prices are 0! This is because all characters after the first non-number are interpreted as 0. That's where acts_as_currency comes in. Add it to your model and pass in any price fields, and they will all be able to take a '$'. Hope you enjoy! If you have any questions, please feel free to contact me at joe@faithfulgeek.org.

Joe Fiorini

http://www.faithfulgeek.org/2008/3/26/acts_as_currency-released

git://github.com/faithfulgeek/acts_as_currency.git

Rails' (MIT)

  • Currently 0.0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Assets

Tags

Comments

Add a comment

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?