首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ActiveAdmin number_to_currency助手

ActiveAdmin number_to_currency助手
EN

Stack Overflow用户
提问于 2014-05-21 11:06:28
回答 1查看 1.9K关注 0票数 3

我通过ActiveAdmin构建了一个管理接口。我有一些资源,如产品,在产品我有一个文章,标题,描述和价格栏。一切运行良好,但我有一个小问题,在Price列中,我默认使用helper number_to_currency,作为美元显示货币。我想以本地货币显示价格,所以在这里我有一个问题:如何实现此助手以本地货币显示价格(例如FR、AUD或RUB)。

Rails 4.1.0

ActiveAdmin 1.0.0

ruby 2.1

app/admin/product.rb

代码语言:javascript
复制
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

代码语言:javascript
复制
class Product < ActiveRecord::Base

    # Relationship
    belongs_to :article

    # Validations
    validates :article, :title, :description, :price, :presence => true
end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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

代码语言:javascript
复制
ru:
  number:
    currency:
      format:
        delimiter: ! ','
        format: ! '%n %u'
        precision: 2
        separator: '.'
        unit: руб.
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23781427

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档