Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在Spree中更改产品价格的货币格式_Ruby On Rails_Spree - Fatal编程技术网

Ruby on rails 在Spree中更改产品价格的货币格式

Ruby on rails 在Spree中更改产品价格的货币格式,ruby-on-rails,spree,Ruby On Rails,Spree,我正在将spree从spree 1.0升级到1.3,并使用新的货币选项 我想将价格呈现为:'100欧元',但得到的是'100欧元'。如何获得单位和值之间的空间 注意:更改区域设置文件不起作用,因为它使用money gem。有很多方法可以做到这一点。最简单的可能是用不同的符号重新注册欧元 将以下内容放入初始值设定项中: # encoding: utf-8 Money::Currency.register({ :priority => 1, :iso_code

我正在将spree从spree 1.0升级到1.3,并使用新的货币选项

我想将价格呈现为:'100欧元',但得到的是'100欧元'。如何获得单位和值之间的空间


注意:更改区域设置文件不起作用,因为它使用money gem。

有很多方法可以做到这一点。最简单的可能是用不同的符号重新注册欧元

将以下内容放入初始值设定项中:

# encoding: utf-8
Money::Currency.register({
    :priority        => 1,
    :iso_code        => "EUR",
    :iso_numeric     => "978",
    :name            => "Euro",
    :symbol          => "€ ",
    :subunit         => "Cent",
    :subunit_to_unit => 100,
    :separator       => ".",
    :delimiter       => "," 
})
rails控制台现在报告:

> Spree::Money.new(100, currency: 'EUR')
=> € 100.00 
非常感谢。 在我的例子中,使用以下命令来更改由to_html方法生成的符号,以防任何人有相同的问题

# encoding: utf-8
Money::Currency.register({
    :priority        => 1,
    :iso_code        => "CLP",
    :iso_numeric     => "152",
    :name            => "Chilean Peso",
    :symbol          => "$",
    :subunit         => "Peso",
    :subunit_to_unit => 1,
    :separator       => ",",
    :delimiter       => ".",
    html_entity: "$"
})

我在我的
config/initializers/spree.rb中执行了以下操作以插入不同的符号:

Money::Currency.table[:chf].merge!(symbol: 'CHF ')

这样货币就不会混淆。

我在初始化器中解决了以下问题,例如
config/initializers/currency\u formatting.rb

# Display prices with a space between symbol and number:
Spree::Money.default_formatting_rules[:symbol_before_without_space] = false
这与中的格式规则挂钩,该规则可以控制所有符号,包括在符号和数字之间放置空格的规则。与本文介绍的其他解决方案相比,该解决方案的优点是可以同时适用于所有货币