#
# this is my latest favourite way to use helper methods in both controllers and models
#

#
# setup a class that will contain all the methods and handle on a controller
#
  class Helper
    ActionView::Helpers.constants.grep(/Helper/i).each do |const|
      include ActionView::Helpers.const_get(const)
    end
    attr_accessor 'controller'
  end

#
# setup a method that runs code in one of these.  note that we only need *one*
# for all our controllers and thus use an @@var
#
  class ApplicationController < ActionController::Base
    cattr 'current'
    before_filter{|controller| ApplicationController.current = controller}

  protected
    def helper &block
      @@helper ||= Helper.new
      @@helper.controller = ApplicationController.current
      block ? @@helper.instance_eval(&block) : @@helper
    end
  end

#
# same gig for models
#
  class ActiveRecord::Base
    def helper &block
      @@helper ||= Helper.new
      @@helper.controller = ApplicationController.current
      block ? @@helper.instance_eval(&block) : @@helper
    end
  end

#
# and now we can do things like
#

  class FooController < ApplicationController
    def bar
      render :text => helper{ link_to 'foo', 'bar' }
    end
  end

#
# and this
#

  class Bar < ActiveRecord::Base
    before_save do
      self.field = helper.strip_tags(field)
    end
  end

#
# bugger writing all that stuff again just because rails decided it was
# useless outside the view.  luckily ruby makes possible this DRY jailbreak.
#