ruby on rails - calculate payments in different currencies -
i have table items wich have string "usd" or "eur".
create in controller variable
def index ... @currencydebt = currencyrate.find( :all, :conditions => ["created_at < ? , currency_id = ?", date.today, 2], :order => ["created_at desc"], :limit => 1 ) ... end
witch find last currency usd
** in view**
<% res in @items %> <% loc in @currencydebt %> <%= number_with_precision(((loc.rate.round(2) * res.payment)), 2) %> <% end %> <% end %>
Аnd result showing paymant in currency usd.
how can show 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 |t| t.string "name" t.string "currency" t.decimal "payment" ... end create_table "currency_rates", :force => true |t| t.integer "currency_id" t.decimal "rate" ... end create_table "currencies", :force => true |t| t.string "name" #usd or eur t.string "short_name" end
firstly, handling currency tricky. there gems ease pain this.
to solve immediate problem though, must decide first on base currency. assuming want keep usd base currency, use gem switch between whatever currency want.
Comments
Post a Comment