在 rails3 中的控制器上使用 number_with_precision [英] Using number_with_precision on controller in rails3

查看:32
本文介绍了在 rails3 中的控制器上使用 number_with_precision的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在控制器上使用这个辅助方法.有什么办法可以实现吗?

I want to use this helper method on controller. Any way to achieve this?

推荐答案

这可能不是一个好主意,但如果您必须这样做,请像这样包含帮助程序:

Probably not a great idea, but if you must, include the helper like so:

class WhateverController
  include ActionView::Helpers::NumberHelper

  def show
    render :text => number_with_precision(2342.234, :precision => 2)
  end

end

这篇关于在 rails3 中的控制器上使用 number_with_precision的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆