要将输入字段中的文本格式设置为货币。找到this解决方案。
所以输入构建器看起来像这样:
def input_group(currency, merged_input_options)
"#{@builder.text_field(attribute_name, merged_input_options)} #{currency_addon(currency)}".html_safe
end但我仍然需要强制小数格式的值:
= f.input :price, as: :currency, input_html: { value: number_with_precision(f.object.price, precision: 2) }是否有可能改进builder而不是将数字格式化为十进制本身?
谢谢
发布于 2016-08-30 02:09:49
你需要def input group返回一个浮点值吗?如果是这样,你有没有尝试过简单的to_f?http://apidock.com/ruby/String/to_f
https://stackoverflow.com/questions/39212180
复制相似问题