0
我有表格项目,其中有字符串“USD”或“EUR”。
我在控制变量创建
计算不同货币的付款
def index
...
@currencydebt = CurrencyRate.find(:all,
:conditions => ["created_at < ? and currency_id = ?", Date.today, 2],
:order => ["created_at DESC"], :limit => 1)
...
end
巫找到最后的货币美元
**在我看来**
<% for res in @items %>
<% for loc in @currencydebt %>
<%= number_with_precision(((loc.rate.round(2) * res.payment)), 2) %>
<% end %>
<% end %>
Аnd作为显示货币美元paymant结果。
但是,如果货品中有字符串美元,我怎么做才会显示付款结果为美元,如果货品中有欧元支付结果为欧元?
我的ActiveRecord
create_table "items", :force => true do |t|
t.string "name"
t.string "currency"
t.decimal "payment"
...
end
create_table "currency_rates", :force => true do |t|
t.integer "currency_id"
t.decimal "rate"
...
end
create_table "currencies", :force => true do |t|
t.string "name" #USD or EUR
t.string "short_name"
end
看看这个钱宝石和谷歌货币:http://stackoverflow.com/questions/10199301/rails-3-1-multiple-currencies或http://stackoverflow.com/questions/1019939/ruby- on-rails-best-method-of-handling-currency-money – rmagnum2002
不幸的是我使用rails 2.0,不使用gems – Andrew