ruby-on-rails - 帮助器中未定义的 Number_to_currency (是视图或控制器的帮助器吗?)
问题描述
我的视图有一个助手,但是当我尝试该cost_dollar
方法时得到一个未定义的方法“number_to_currency”。
应用程序/helpers/books_helper.rb
Module BooksHelper
require 'action_view'
include ActionView::Helpers::NumberHelper
def cost_dollar
@book.cost.number_to_currency
end
end
解决方案
你应该使用 number_to_currency(value) 而不是 value.number_to_currency
def cost_dollar
number_to_currency(@book.cost)
end
推荐阅读
- python - 无头浏览器与 Youtube 一起使用
- javascript - Flow 中的联合数组类型。类型 A 中缺少属性,但类型 B 中存在
- angular - goBack 路由后重新加载选项卡视图(Ionic 4)
- ember.js - Ember:从导入的 mixin 中覆盖属性?
- python - 登录后将用户带到新页面的Tkinter登录页面?
- python - 根据关联值将值连接到多列
- python - Keras evaluate() 和 predict() 结果太离谱了
- c# - 从字符串创建到文件夹的链接
- java - 使用数组的有界集的添加/删除操作的最坏情况场景时间复杂度?
- php - 将数据库上的 http 更改为 https,现在管理页面上的 404