Money
The Money
field is used to display a monetary value.
ruby
field :price, as: :money, currencies: %w[EUR USD RON PEN]
Money Field Example
You can explore the implementation of the money field in avodemo and it's corresponding code on GitHub here
Example on new
Example on show with currencies USD
Example on show with currencies RON
Example on index
Installation
This field is a standalone gem. You have to add it to your Gemfile
alongside the money-rails
gem.
Add this field to the Gemfile
ruby
# Gemfile
gem "avo-money_field"
gem "money-rails", "~> 1.12"
Important: Monetization Requirement
In order to fully utilize the money field's features, you must monetize the associated attribute at the model level using the monetize
method from the money-rails
gem. (Usage example)
For example:
ruby
monetize :price_cents
Without this step, the money field may not behave as expected, and the field might not render.