ActiveAdmin number_to_currency helper
activeadmin, locale, ruby, ruby-on-rails-4
Solution
Use the `:locale` parameter. From the documentation:
Options
:locale - Sets the locale to be used for formatting (defaults to current locale)
...snip...
number_to_currency(1234567890.506, locale: :fr) # => 1 234 567 890,51 €
To add support for a locale you need to have a `<locale>.yml` under `config/locale`, for example:
ru.yml
ru:
number:
currency:
format:
delimiter: ! ','
format: ! '%n %u'
precision: 2
separator: '.'
unit: руб.
Problem
I building a administration interface via ActiveAdmin. I have some resources like Products, at the Products i have an Article, Title, Description and Price columns. Everything working well, but i have a little problem, at the Price column i use helper number_to_currency, by default ActiveAdmin display currency as USD. I want to display prices in local currency, so and here i have a question how to implement this helper to display price in local currency (for example FR, AUD or RUB). Rails 4.1.0 ActiveAdmin 1.0.0 ruby 2.1 app/admin/product.rb ``` ActiveAdmin.register Product do # Permitted parameters permit_params :article_id, :title, :description, :price # Displayed columns index do column :article, :sortable => :article column :title column :description # Currency helper column :price, :sortable => :price do |cur| number_to_currency cur.price end default_actions end end ``` app/models/product.rb ``` class Product < ActiveRecord::Base # Relationship belongs_to :article # Validations validates :article, :title, :description, :price, :presence => true end ```