我有一个自定义助手模块CalendarHelper。然后,我的一些视图使用自定义帮助程序方法来显示日历。
当我尝试在我的自定义帮助程序中使用任何视图助手时,例如number_to_currency(),即使我添加了
,我也会收到未定义的方法错误include ActionView::Helpers::NumberHelper
到我的CalendarHelper。
我还尝试在application_helper中添加一个方法:
def as_dollars_pretty(price)
number_to_currency(price, :precision => 2, :unit => '$')
end
然后在我的自定义助手中添加了
include ApplicationHelper
但是当我尝试在我的自定义日历助手中使用as_dollars_pretty(123.45)时,我得到了相同的未定义方法错误。
答案 0 :(得分:2)
这对我有用
module TestHelper
include ActionView::Helpers::NumberHelper
def foo
number_to_currency 123
end
end
include TestHelper
puts foo