Mini John
Mini John

Reputation: 7941

undefined method pluralize for main:Object

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?

Upvotes: 13

Views: 3594

Answers (1)

Dylan Markow
Dylan Markow

Reputation: 124429

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"

Upvotes: 27

Related Questions