public
Description: Allows you to enter a '$' in fields stored as decimal but are actually currency types
Homepage: http://www.faithfulgeek.org/2008/3/26/acts_as_currency-released
Clone URL: git://github.com/faithfulgeek/acts_as_currency.git
Search Repo:
Added readme file
Joe Fiorini (author)
Tue Mar 25 23:43:06 -0700 2008
commit  19f4316851fd9ff7f1b52130605634cc3e93bd1b
tree    959f86f9fa1e5cd954a695564c4f64692e98cba9
parent  9f36b48c6ce640bccbaf01d6647fc7ab283642d8
0
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
0
@@ -1 +1,45 @@
0
+ActsAsCurrency
0
+==============
0
+
0
+There's a problem in ActiveRecord. Let's say you have a field in a table that's supposed to be money, for example:
0
+
0
+add_column :products, :price, :decimal
0
+
0
+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.
0
+
0
+Install
0
+=======
0
+
0
+This project is hosted on github. There are a few options for installing it.
0
+
0
+#1 Using git-rails gem
0
+ - This is by far the easiest method. Install git-rails by issuing:
0
+ sudo gem install git-rails (Windows: gem install git-rails)
0
+ git-rails install git://github.com/faithfulgeek/acts_as_currency.git
0
+
0
+#2 Using git-clone
0
+ - This method requires that you have Git installed (might as well do it, it's a great alternative to svn)
0
+ - Assumes your current working directory is your rails app root
0
+ cd vendor/plugins
0
+ git-clone git://github.com/faithfulgeek/acts_as_currency.git acts_as_currency
0
+
0
+#3 Source Tarball
0
+ - If you cannot access Git at all, use this link http://github.com/faithfulgeek/acts_as_currency/tarball/master to download the source tarball
0
+ cd vendor/plugins
0
+ mkdir acts_as_currency && cd acts_as_currency
0
+ tar xvcf faithfulgeek-acts-as-currency-master.tar.gz
0
+
0
+Troubles? Let me know! joe@faithfulgeek.org
0
+
0
+Example
0
+=======
0
+
0
+class Product < ActiveRecord::Base
0
+ acts_as_currency :price, :discount_price
0
+end
0
+
0
+For an example of the problem and how acts_as_currency solves it, please see specs/acts_as_currency_spec.rb. If you have rspec installed you can play around with different values and see how it all works.
0
+
0
+
0
+Copyright (c) 2008 Joe Fiorini, released under the MIT license

Comments

    No one has commented yet.