是否可以使用" number_to_currency"在控制器内?

时间:2014-04-22 01:32:39

标签: ruby-on-rails ruby-on-rails-4

我a,在表单中构建一个下拉菜单,以这种形式显示可用选项及其价格的列表:“service - price”。然而,我的问题是它看起来不像我可以在我的控制器中使用number_to_currency。有没有其他方法可以实现相同的效果,或从我的控制器访问number_to_currency?这是我最初的努力:

@levels = []
DistributorLevel.all.each do |d|
  price = (d.price > 0) ? number_to_currency(d.price) : "Free"
  @levels << ["#{d.name} - #{price}", d.id]
end

2 个答案:

答案 0 :(得分:26)

是的,你可以这样做:

view_context.number_to_currency(d.price) 

ActionController::Base.helpers.number_to_currency(d.price) 

答案 1 :(得分:2)

尝试:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration
相关问题