<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>opensoul.org - acts_as_money Changes</title>
  <id>tag:opensoul.org,2010:/2006/11/13/acts_as_money/changes</id>
  <generator version="0.8.0" uri="http://mephistoblog.com">Mephisto Drax</generator>
  <link href="http://opensoul.org/2006/11/13/acts_as_money/changes.xml" rel="self" type="application/atom+xml"/>
  <link href="/2006/11/13/acts_as_money" rel="alternate" type="text/html"/>
  <updated>2008-06-19T23:29:10Z</updated>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>brandon</name>
    </author>
    <id>tag:opensoul.org,2008-06-19:451:3</id>
    <published>2006-11-13T19:11:00Z</published>
    <updated>2008-06-19T23:29:10Z</updated>
    <link href="http://opensoul.org/2006/11/13/acts_as_money" rel="alternate" type="text/html"/>
    <title>acts_as_money</title>
<content type="html">&lt;p&gt;At &lt;a href=&quot;http://collectiveidea.com&quot;&gt;Collective Idea&lt;/a&gt;, we often try to take pieces of code that we use often and extract them into plugins.  We&#8217;re trying to get better about making them available, so, here we go:&lt;/p&gt;


&lt;code&gt;acts_as_money&lt;/code&gt; is a fairly trivial plugin that has proved to be very useful.  It just makes it a little easier to work with the &lt;a href=&quot;http://rubyforge.org/projects/money/&quot;&gt;money&lt;/a&gt; gem.

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;class Product &amp;lt; ActiveRecord::Base
  money :price
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This assumes that there are 2 columns in the database, &lt;code&gt;cents&lt;/code&gt; (integer) and &lt;code&gt;currency&lt;/code&gt; (string).  These fields can be changed by setting the :cents and :currency options.  To use the default currency, you can simple set :currency option to false and not have a currency field.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;class Room &amp;lt; ActiveRecord::Base
  money :rate, :cents =&amp;gt; :rate_in_cents, :currency =&amp;gt; :rate_currency
  money :discount, :cents =&amp;gt; :discount_in_cents, :currency =&amp;gt; false
end&lt;/code&gt;&lt;/pre&gt;

&lt;code&gt;acts_as_money&lt;/code&gt; also incorporates a &lt;a href=&quot;http://dev.rubyonrails.org/ticket/6322&quot;&gt;patch to &lt;code&gt;composed_of&lt;/code&gt;&lt;/a&gt; that I submitted to core that allows you to pass a String, Fixnum, Float or Money object as a parameter to the setter, and it will call #to_money to convert it to a Money object.  This makes it convenient for using money fields in forms.

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;r = Room.new :rate =&amp;gt; &amp;quot;100.00&amp;quot;
r.rate                            # returns &amp;amp;lt;Money:0x249ef9c @currency=&amp;quot;USD&amp;quot;, @cents=10000&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;

	&lt;h3&gt;Installation&lt;/h3&gt;


&lt;pre&gt;
script/plugin install git://github.com/collectiveidea/acts_as_money.git
&lt;/pre&gt;

	&lt;p&gt;Hope you find this useful.  I know I&#8217;ve been using it in any app that handles money, and it&#8217;s been a time saver.  Allowing me to use a &lt;code&gt;composed_of&lt;/code&gt; field in forms has been extremely helpful.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>brandon</name>
    </author>
    <id>tag:opensoul.org,2006-11-13:166:2</id>
    <published>2006-11-13T19:11:00Z</published>
    <updated>2006-11-13T19:13:26Z</updated>
    <link href="http://opensoul.org/2006/11/13/acts_as_money" rel="alternate" type="text/html"/>
    <title>acts_as_money</title>
<content type="html">&lt;p&gt;At &lt;a href=&quot;http://collectiveidea.com&quot;&gt;Collective Idea&lt;/a&gt;, we often try to take pieces of code that we use often and extract them into plugins.  We&#8217;re trying to get better about making them available, so, here we go:&lt;/p&gt;


&lt;code&gt;acts_as_money&lt;/code&gt; is a fairly trivial plugin that has proved to be very useful.  It just makes it a little easier to work with the &lt;a href=&quot;http://rubyforge.org/projects/money/&quot;&gt;money&lt;/a&gt; gem.

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;class Product &amp;lt; ActiveRecord::Base
  money :price
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This assumes that there are 2 columns in the database, &lt;code&gt;cents&lt;/code&gt; (integer) and &lt;code&gt;currency&lt;/code&gt; (string).  These fields can be changed by setting the :cents and :currency options.  To use the default currency, you can simple set :currency option to false and not have a currency field.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;class Room &amp;lt; ActiveRecord::Base
  money :rate, :cents =&gt; :rate_in_cents, :currency =&gt; :rate_currency
  money :discount, :cents =&gt; :discount_in_cents, :currency =&gt; false
end&lt;/code&gt;&lt;/pre&gt;

&lt;code&gt;acts_as_money&lt;/code&gt; also incorporates a &lt;a href=&quot;http://dev.rubyonrails.org/ticket/6322&quot;&gt;patch to &lt;code&gt;composed_of&lt;/code&gt;&lt;/a&gt; that I submitted to core that allows you to pass a String, Fixnum, Float or Money object as a parameter to the setter, and it will call #to_money to convert it to a Money object.  This makes it convenient for using money fields in forms.

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;r = Room.new :rate =&gt; &quot;100.00&quot; 
r.rate                            # returns &amp;lt;Money:0x249ef9c @currency=&quot;USD&quot;, @cents=10000&amp;gt;&lt;/code&gt;&lt;/pre&gt;

	&lt;h3&gt;Installation&lt;/h3&gt;


&lt;pre&gt;
script/plugin install -x http://source.collectiveidea.com/public/rails/plugins/acts_as_money
&lt;/pre&gt;

	&lt;p&gt;Hope you find this useful.  I know I&#8217;ve been using it in any app that handles money, and it&#8217;s been a time saver.  Allowing me to use a &lt;code&gt;composed_of&lt;/code&gt; field in forms has been extremely helpful.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>brandon</name>
    </author>
    <id>tag:opensoul.org,2006-11-13:165:1</id>
    <updated>2006-11-13T19:10:18Z</updated>
    <link href="http://opensoul.org/2010/3/17/acts_as_money" rel="alternate" type="text/html"/>
    <title>acts_as_money</title>
<content type="html">&lt;p&gt;At &lt;a href=&quot;http://collectiveidea.com&quot;&gt;Collective Idea&lt;/a&gt;, we often try to take pieces of code that we use often and extract them into plugins.  We&#8217;re trying to get better about making them available, so, here we go:&lt;/p&gt;


&lt;code&gt;acts_as_money&lt;/code&gt; is a fairly trivial plugin that has been very useful.  It just makes it a little easier to work with the &lt;a href=&quot;http://rubyforge.org/projects/money/&quot;&gt;money&lt;/a&gt; gem.

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;class Product &amp;lt; ActiveRecord::Base
  money :price
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This assumes that there are 2 columns in the database, &lt;code&gt;cents&lt;/code&gt; (integer) and &lt;code&gt;currency&lt;/code&gt; (string).  These fields can be changed by setting the :cents and :currency options.  To use the default currency, you can simple set :currency option to false and not have a currency field.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;class Room &amp;lt; ActiveRecord::Base
  money :rate, :cents =&gt; :rate_in_cents, :currency =&gt; :rate_currency
  money :discount, :cents =&gt; :discount_in_cents, :currency =&gt; false
end&lt;/code&gt;&lt;/pre&gt;

&lt;code&gt;acts_as_money&lt;/code&gt; also incorporates a &lt;a href=&quot;http://dev.rubyonrails.org/ticket/6322&quot;&gt;patch to &lt;code&gt;composed_of&lt;/code&gt;&lt;/a&gt; that I submitted to core that allows you to pass a String, Fixnum, Float or Money object as a parameter to the setter, and it will call #to_money to convert it to a Money object.  This makes it convenient for using money fields in forms.

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;r = Room.new :rate =&gt; &quot;100.00&quot; 
r.rate                            # returns &lt;/code&gt;&lt;/pre&gt;

	&lt;h3&gt;Installation&lt;/h3&gt;


&lt;pre&gt;
script/plugin install -x http://source.collectiveidea.com/public/rails/plugins/acts_as_money
&lt;/pre&gt;

	&lt;p&gt;Hope you find this useful.  I know I&#8217;ve been using it in any app that handles money, and it&#8217;s been a time saver.  Allowing me to use a &lt;code&gt;composed_of&lt;/code&gt; field in forms has been extremely helpful.&lt;/p&gt;</content>  </entry>
</feed>
