本文介绍了main:Object 的未定义方法复数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在我的控制台中测试一个方法,但即使是基本的复数形式 -
I'm trying to test a method in my console, but even the basic pluralize -
pluralize(1, 'person')
行不通..
输出:
NoMethodError: undefined method 'pluralize' for main:Object
from (pry):42:in '<main>'
但是 helper.method(:pluralize)
显示我: Method: ActionView::Base(ActionView::Helpers::TextHelper)#pluralize
我错过了什么?
推荐答案
默认情况下,控制台中不包含帮助程序.您可以先包含它们,它会起作用:
The helpers aren't included by default in the console. You can include them first and it'll work:
>> include ActionView::Helpers::TextHelper
>> pluralize(1, 'person')
# => "1 person"
或者,您可以使用 Rails 在控制台中为您提供的 helper
对象:
Or, you can use the helper
object which Rails gives you in the console:
>> helper.pluralize(1, 'person')
# => "1 person"
这篇关于main:Object 的未定义方法复数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!