Ruby on rails 如何从金钱宝石中获取符号

Ruby on rails 如何从金钱宝石中获取符号,ruby-on-rails,ruby-on-rails-3,currency,Ruby On Rails,Ruby On Rails 3,Currency,我使用money gem在我的产品模型中表示货币字段。 这是我的密码: 产品型号: composed_of :price, :class_name => "Money", :mapping => [%w(price cents), %w(currency currency_as_string)], :constructor => Proc.new { |cents, currency| Money

我使用money gem在我的产品模型中表示货币字段。 这是我的密码:

产品型号:

          composed_of :price, 
          :class_name => "Money",
          :mapping => [%w(price cents), %w(currency currency_as_string)],
          :constructor => Proc.new { |cents, currency| Money.new(cents || 0, currency || Money.default_currency) },
          :converter => Proc.new { |value| value.respond_to?(:to_money) ? value.to_money : raise(ArgumentError, "Can't convert #{value.class} to Money") }
  • 在我的模型中,像currency和price这样的字段都是字符串
我的表单视图

 <li>
  <%= f.select(:currency,all_currencies(Money::Currency::TABLE), {:include_blank => 'Select a Currency'}, :class => "styled" )%>
 </li>
  • '选择货币'},:class=>“已设置样式”)%>
  • 在我的产品助手中

    def all_currencies(hash)
        hash.inject([]) do |array, (id, attributes)|
          array ||= []
          array << [attributes[:name], attributes[:iso_code]]
          array
        end
      end
    
    def所有货币(散列)
    hash.inject([])do |数组(id,属性)|
    数组| |=[]
    
    符号数组你的意思是美元换美元,印度卢比也一样吗?是的,但我解决了这个问题problem@AnidhyaAhuja你能说说你是如何解决这个问题的吗?@swatiagarwal问题下面提到了解决方案。我必须在助手中获得符号和其他属性。
    def all_currencies(hash)
        hash.inject([]) do |array, (id, attributes)|
          array ||= []
          array << [attributes[:name], attributes[:iso_code],attributes[:symbol]]
          array
        end
      end