Rails: Undefined method `truncate' in model
In rails include:
include ActionView::Helpers::TextHelper
but if you want to tested in Ruby irb:
require 'action_view'
include ActionView::Helpers::TextHelper
You're using it wrong, you should be calling this method on a String
. See truncate
's signature.
Use:
if description.length > nb_words_max
description.truncate(nb_words_max, :separator => ' ') + " ..."
else
...