Search code examples
ruby-on-railsruby-on-rails-4pluralizeundefined-function

Undefined method 'pluralize' for #<Controller>


Not sure why this has decided to stop working.

customers_controller.rb

redirect_to customers_url,
            notice: pluralize(@imported_customers.size, "customer") + " imported!"

And I'm getting the error:

NoMethodError: undefined method 'pluralize' for #CustomersController:0x007f3ca8378a20

Any idea where to start looking?


Solution

  • If you don't want to use view helpers, then you can use String#pluralize:

    "customer".pluralize(@imported_customers.size)
    

    If you want to use view helpers then you should include the respective helper as another answers or just use ActionView::Rendering#view_context:

    view_context.pluralize(@imported_customers.size, "customer")