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