Format currencies

This commit is contained in:
Manuel Bustillo 2024-07-11 20:06:48 +02:00
parent 8bac32bb77
commit 2f8f3404bb
4 changed files with 11 additions and 2 deletions

View File

@ -61,3 +61,4 @@ group :development do
# gem "spring"
end
gem "money"

View File

@ -117,6 +117,8 @@ GEM
marcel (1.0.4)
mini_mime (1.1.5)
minitest (5.24.1)
money (6.16.0)
i18n (>= 0.6.4, <= 2)
msgpack (1.7.2)
mutex_m (0.2.0)
net-imap (0.4.14)
@ -252,6 +254,7 @@ DEPENDENCIES
debug
importmap-rails
jbuilder
money
pg (~> 1.1)
puma (>= 5.0)
rails (~> 7.1.3, >= 7.1.3.2)

View File

@ -12,14 +12,14 @@
<% @expenses.each do |expense| %>
<tr>
<td><%= expense.name %></td>
<td><%= expense.amount %></td>
<td><%= expense.amount.to_currency %></td>
<td><%= link_to "Show", expense %></td>
<td><%= link_to "Edit", edit_expense_path(expense) %></td>
</tr>
<% end %>
<tr>
<td>Total</td>
<td><%= @expenses.sum(&:amount) %></td>
<td><%= @expenses.sum(&:amount).to_currency %></td>
<td colspan="2"></td>
</tr>
</table>

View File

@ -0,0 +1,5 @@
class Numeric
def to_currency
Money.from_amount(self, "EUR").format
end
end