Mixing in action view helper methods in a class

I’ve got a class where I would like to use the TextHelper truncate
method. It’s not a M, V or C but is called by a controller. I
figured I should be able to mixin the TextHelper in order to have
access to the truncate method. But I can’t get it to work. I’m new
to Ruby and ROR, so I haven’t done mixins before.

Here’s what I’ve got…

class Searcher
require ‘action_view/helpers/text_helper’
include ActionView::Helpers::TextHelper

I get a NoMethodError: undefined method `truncate’ for
Searcher:Class. How do I get this to work?

By the way, I apologize if this has already been answered in this
group (as is likely), but I did a search and couldn’t find it.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs