undefined method pluralize for main:Object

白昼怎懂夜的黑 提交于 2019-12-18 19:03:51

问题


I'm trying to test a method in my console, but even the basic pluralize -

pluralize(1, 'person')

wont work..

Output:

NoMethodError: undefined method 'pluralize' for main:Object
from (pry):42:in '<main>'

but helper.method(:pluralize) shows me : Method: ActionView::Base(ActionView::Helpers::TextHelper)#pluralize

What am i missing?


回答1:


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"

Or, you can use the helper object which Rails gives you in the console:

>> helper.pluralize(1, 'person')
# => "1 person"


来源:https://stackoverflow.com/questions/25061838/undefined-method-pluralize-for-mainobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!