DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Use Rails Helper Methods In Controller

  • submit to reddit
        I wanted to use a helper method in the controller and I found the following trick in In any controller, there is a <strong>@template</strong>-instance and we can call helper methods like pluralize or strip_tags on it:
class XyController < ApplicationController
  def process_text
    @html = ..
    @ascii = @template.strip_tags(@html)   # call helper method strip_tags
Ryan is not sure if this use is intended, but it's clear, short and with the current rails version it works fine.

Of cause the explicit call with full path 
works in the controller like everywhere else.