Skip to content

Why is the currency ignored on assignment? #87

skorfmann opened this Issue Mar 3, 2013 · 7 comments

6 participants


In the following example, the currency of the assigned money object is just silently ignored:

class Item < ActiveRecord::Base  
  monetize :price_cents

i =
i.price =, 'AUD') 
i.price # => <Money fractional:500 currency:USD>

That's totally confusing and not the way I've expected it to work. What's the idea behind this behaviour?


Do you have instance-level currency? If so, what is the name of your currency attribute?

If it's anything other than currency, you may need the :with_model_currency option.

If your currency attribute is price_currency, try:

monetize :price_cents, :with_model_currency => :price_currency
swistak commented Apr 9, 2013

I had the same issue.
Setting :with_model_currency works, but this is not expected behaviour. According to documentation this should not be needed as migration helper created price_currency.

Also assigning values like "400 GBP" which are perfectly fine with Money.parse is ignored.

swistak commented Apr 9, 2013

I've dug into code and looks like money-rails is hardcoding one currency column per row instead of amount / currency pairs that money helper generates. As a result it's for example impossible to have 2 columns with different currencies.

Will work on fix for that in spare time. .monetize needs serious refactoring.

aboutlo commented May 29, 2013

I'm stuck on a similar problem. I have the column price where I fill prices in GBP, EUR and USD currencies. Unfortunately all my price are not based on currency stored into the model but on default currency.
I'm using a workaround like, myproduct.price_currency) to regenerate the right money object.

RubyMoney member
alup commented May 29, 2013

@aboutlo Take a look at this
The "instance currency column" should be named after currency, else you may need the :with_model_currency option as @geehsien mentioned.

aboutlo commented May 30, 2013

thank you, it works. I missed the @geehsien tip. IMHO should be the default behavior or at least added to the page.

@alup alup closed this Jun 12, 2013

Cool ! @geehsien

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.