3
votes

I have a Rails 4 app using the money-rails gem to define money objects. I have a money object called default_price_cents and a currency column on the User model to define currencies for each individual user (as seen here):

class AddDefaultsToUser < ActiveRecord::Migration
  def change
    add_money :users, :default_price
    add_column :users, :currency, :string
  end
end

My user.rb has the following lines:

register_currency :usd

monetize :default_price_cents, with_model_currency: :default_price_currency

Users then define their currency in registration (HAML):

.form-group
  = f.label :currency
  = f.select :default_price_currency, [['USD','usd'],['CAD','cad'],['DKK','dkk']]

I have tried to have this set with both :default_price_currency as well as :currency.

In my view, I have:

humanized_money_with_symbol @default_price

The Problem:

When this I display the default price in my view, it for some reason uses the currency I have defined with register_currency in my model, instead of using the currency defined by the user upon registration. How do I get the app to refer to the user defined currency instead of the registered currency for that model?

1

1 Answers

1
votes

SOLVED!

Well, embarrassingly, writing this post helped me to find the answer only a few seconds later. I'll leave it up for anyone who may need it.

I've changed this line in user.rb:

monetize :default_price_cents, with_model_currency: :default_price_currency

to look like

monetize :default_price_cents, with_model_currency: :currency

as well as changed the default_price_currency to currency in my views.