我正在尝试使用我的rails 4应用程序中的money-rails宝石。
我有一个参与者模型,其中的每个货币和participation_cost都有属性。我的目标是让用户为每个实例指定一种货币,以及参与费用的数额。
在我的参与者模型中,我有:
货币化:participation_cost,with_model_currency::amount_currency
在我的表单中,我要求用户选择一种货币,并将金额指定如下:
<%= f.input :participation_cost, label: 'What amount will you pay for participation costs?', :label_html => { :class => 'question-participants' }, placeholder: 'Whole numbers only', :input_html => {:style=> 'width: 250px; margin-top: 20px', class: 'response-participants'} %>
<br><br>
<%= f.input :currency, label: 'Select your costs currency', label_html: {class: 'fundingspace'}, collection: ["AUD Australian Dollars", "GBP British Pounds", "USD US Dollars" ], prompt: "Choose one" %> </div> <br>在我看来,我想显示货币和金额。我现在有一个字符串如下:
<%= "#{@project.scope.try(:participant).try(:participation_cost)} #{@project.scope.try(:participant).try(:currency)}" %>当我测试这个时,我只得到participation_cost的号码。我没拿到那货币。
在我的money.rb首字母中,我有:
config.default_currency = :gbp有人能帮忙吗?我不知道怎么用这个宝石。我遵循了用户指南,但它只涉及建立模型,例如,基于货币的选择。有人为此目的成功地使用过它吗?
谢谢
发布于 2015-05-07 15:57:54
步骤:
add_money :table_name, :participation_cost
Rails 4
add_monetize :table_name, :participation_cost
这将给你两列
:participation_cost_pennies #便士如果英镑,美分如果美元
:participation_cost_currencymonetize :participation_cost_pennies, with_model_currency: :participation_cost_currency如果您不想要结束时的便士或货币列中的participation_cost,您可以在Money.rb中修改它。请参阅here
https://stackoverflow.com/questions/30010565
复制相似问题