作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在将数字插入字符串之前在 Controller 中格式化数字。但是函数 number_with_delimiter() 在 Controller 中不起作用。
我需要将字符串发送到 javascript 插件。
我可以在 View 中运行代码,但我想这不是最好的选择。
@mycarousel_itemList = @mycarousel_itemList + "{url: '" + p.photo.url(:thumb) +
"', price: '" + p.price.to_s + " €'},"
最佳答案
要直接回答您的问题,请在您的 Controller 中包含以下内容(通常靠近顶部,class
声明下方):
include ActionView::Helpers::NumberHelper
p
是什么类),然后编写一个函数来返回格式化的价格。
关于ruby-on-rails - 如何在rails Controller 上的ruby中格式化数字,number_with_delimiter仅在 View 中有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3596075/
我有一个简单的验证: class Product 1000000, :message => "must be less than #{numb
我是一名优秀的程序员,十分优秀!