Use Rails Helper Method In Model
Join the DZone community and get the full member experience.Join For Free
After refactoring I needed a rails helper method in a model. I found the trick to do this in a clean way again in http://railscasts.com/episodes/132-helpers-outside-views. "ActionController::Base.helpers" returns a helper proxy. To get short helper calls Ryan recommends to put it in an extra method, e.g. "helpers".
# models/wikipedia_reader.rb def read!(kword) .. pure_text = helpers.strip_tags(text_with_unwanted_html_tags) .. end def helpers ActionController::Base.helpers end
Opinions expressed by DZone contributors are their own.