RubyMoney/money — Issue #139: create money from form
Author: gerwinov
Created: 2012-02-04 16:45:46+00:00
State: open

Hi,

I'm quite new to Rails and this is the first time I'm using the money git. I inserted the following code into my model, as stated in the money gem wiki:

composed_of :cash,
:class_name => "Money",
:mapping => [%w(amount cents), %w(currency currency_as_string)],
:constructor => Proc.new { |cents, currency| Money.new(cents || 0, currency || Money.default_currency) },
:converter => Proc.new { |value| value.respond_to?(:to_money) ? value.to_money : raise(ArgumentError, "Can't convert #{value.class} to Money") }

In my database I have two fields: amount (integer) and currency (string)

I also have a form, were users can enter a certain cash-amount:

<%= f.number_field :amount %>

The problem here is that users fill in their amount like 1,50 instead of 150 cents. What is the best way to convert the user input of 1,50 to 150 before inserting this into the database?

Regards,
Gerwin