我通过ActiveAdmin构建了一个管理接口。我有一些资源,如产品,在产品我有一个文章,标题,描述和价格栏。一切运行良好,但我有一个小问题,在Price列中,我默认使用helper number_to_currency,作为美元显示货币。我想以本地货币显示价格,所以在这里我有一个问题:如何实现此助手以本地货币显示价格(例如FR、AUD或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
endapp/models/product.rb
class Product < ActiveRecord::Base
# Relationship
belongs_to :article
# Validations
validates :article, :title, :description, :price, :presence => true
end发布于 2014-05-21 11:14:16
使用:locale参数。来自文档
选项
:locale -设置用于格式化的区域设置(默认为当前区域设置)
...snip...
number_to_currency(1234567890.506,地区::fr) # => 1 234 567 890,51欧元
要添加对区域设置的支持,需要在config/locale下设置一个config/locale,例如:
ru.yml
ru:
number:
currency:
format:
delimiter: ! ','
format: ! '%n %u'
precision: 2
separator: '.'
unit: руб.https://stackoverflow.com/questions/23781427
复制相似问题