Ruby   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – Money-Rails Gem – 实例货币大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的rails 4应用程序中有一个模型称为资金.

我正在使用Money Rails来处理货币/货币组件 – https://github.com/RubyMoney/money-rails

我的资金模型有3个资金属性叫做amount_expenses,amount_honorarium和amount_principal_financing.

资金模型还具有用于创建实例的用户的货币属性,以选择应该为三个资金属性中的每一个使用哪种货币.

当我运行迁移到add_monetize到三个资金属性中的每一个时,它创建了三个相应的货币属性.

我需要它们吗?我可以要求用户为每个实例选择一次货币,然后使用该货币保存三个供资属性吗?那会怎么样?如果我在资金表中只有一个货币属性,那么货币化是否会知道如何选择显示三种融资金额?

资金表有:

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",null: false
    t.String   "amount_honorarium_currency",null: false
    t.Integer  "amount_principal_financing_pennies",null: false
    t.String   "amount_principal_financing_currency",null: false

结束

谢谢

解决方法

对于你们三个领域,你可以简单地写 @H_248_14@monetize :field1,:field2,:field3,with_model_currency: :currency_field

在这种情况下,只有一个货币列就足够了.

大佬总结

以上是大佬教程为你收集整理的ruby-on-rails – Money-Rails Gem – 实例货币全部内容,希望文章能够帮你解决ruby-on-rails – Money-Rails Gem – 实例货币所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。