Money-Rails Gem - instance currencies

I have a model in my rails 4 application called funding.

I use Money Rails to process money / currency components - https://github.com/RubyMoney/money-rails

My financing model has 3 financing attributes called amount_expenses, amount_honorarium and amount_principal_financing.

The financing model also has a currency attribute for the user creating the instance to select which currency should be used for each of the three financing attributes.

When I made the switch to add_monetize for each of the three financing attributes, he created three corresponding currency attributes.

Do I need them? Can I ask the user to select a currency once for each instance, and then save the three financing attributes using this currency? How will it work? If I have only one currency attribute in the financing table, monetize how to choose to display the three funding amounts?

Financing table:

t.boolean "expenses" t.boolean "honorarium" t.boolean "financing" t.string "currency" t.string "size" t.integer "amount_expenses" t.integer "amount_honorarium" t.integer "amount_principal_financing" t.float "return_on_finance" t.integer "period_of_return" t.text "expense_description" t.integer "scope_id" t.integer "amount_expenses_pennies", default: 0, null: false t.string "amount_expenses_currency", default: "GBP", null: false t.integer "amount_honorarium_pennies", default: 0, null: false t.string "amount_honorarium_currency", default: "GBP", null: false t.integer "amount_principal_financing_pennies", default: 0, null: false t.string "amount_principal_financing_currency", default: "GBP", null: false 

end

thanks

+6
source share
1 answer

For all of you, three fields you can simply write

 monetize :field1, :field2, :field3, with_model_currency: :currency_field 

In this case, only one currency column is sufficient.

+6
source

Source: https://habr.com/ru/post/986898/


All Articles