Undefined method 'pluralize' for #<Controller>
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")
By default, the pluralize
method is only made available in your views. To use it in a controller, put this at the top of your controller class:
include ActionView::Helpers::TextHelper
like
# app/controllers/cutomers_controller.rbclass CustomersController < ApplicationController include ActionView::Helpers::TextHelper def index etc. ...
You can call pluralize helper with:
ActionController::Base.helpers.pluralize(@imported_customers.size, "customer") + " imported!"
or
# app/controllers/cutomers_controller.rbclass CustomersController < ApplicationController include ActionView::Helpers::TextHelper