0

I have open rails console and want to use pluralize method but i am getting error as NoMethodError: undefined methodpluralize' for main:Object`

pluralize(1, 'person')

i can see the documentation for this method here http://www.rubydoc.info/docs/rails/4.1.7/ActionView/Helpers/TextHelper#pluralize-instance_method but i don't know how to use this documentation. i have tried below code but it didn't work

ActionView::Helpers::TextHelper.new.puralize(1, 'person')
ActionView::Helpers.new.pluralize(1 , 'person')

Please help

Thanks,

Lokesh Harjani
  • 119
  • 1
  • 9

2 Answers2

2

Use:

include ActionView::Helpers::TextHelper

Not:

ActionView::Helpers::TextHelper.new.puralize(1, 'person')

or

ActionView::Helpers.new.pluralize(1 , 'person')
0

Instead of calling using new:

ActionView::Helpers::TextHelper.new.puralize(1, 'person')
ActionView::Helpers.new.pluralize(1 , 'person')

You should call it using include include ActionView::Helpers::TextHelper. Like below.

include ActionView::Helpers::TextHelper

pluralize(1, 'person')
# => 1 person

pluralize(2, 'person')
# => 2 people

pluralize(3, 'person', 'users')
# => 3 users

pluralize(0, 'person')
# => 0 people
HashRocket
  • 778
  • 1
  • 5
  • 15
  • Ok. so that means if there is module in rubydocinfo then we have to include it and if there is class in rubydocinfo then we have to instantiate and use it .. right?? – Lokesh Harjani Apr 19 '16 at 06:13
  • @Lokesh Harjani, I always call using `include` and/or `require`. If my answer helped you, please accept the answer. Thanks! – HashRocket Apr 19 '16 at 06:16