I have table items wich have string "USD" or "EUR".
I create in my controller variable
def index
...
@currencydebt = CurrencyRate.find( :all,
:conditions => ["created_at < ? and currency_id = ?", Date.today, 2],
:order => ["created_at DESC"], :limit => 1 )
...
end
witch find last currency USD
** in my view**
<% for res in @items %>
<% for loc in @currencydebt %>
<%= number_with_precision(((loc.rate.round(2) * res.payment)), 2) %>
<% end %>
<% end %>
Πnd as a result showing paymant in currency USD.
But how can I do that would show up as a result if have string USD in items Payment result in USD, if have EUR in items Payment result in EUR?
my 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