class Helper
ActionView::Helpers.constants.grep(/Helper/i).each do |const|
include ActionView::Helpers.const_get(const)
end
attr_accessor 'controller'
end
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
class ActiveRecord::Base
def helper &block
@@helper ||= Helper.new
@@helper.controller = ApplicationController.current
block ? @@helper.instance_eval(&block) : @@helper
end
end
class FooController < ApplicationController
def bar
render :text => helper{ link_to 'foo', 'bar' }
end
end
class Bar < ActiveRecord::Base
before_save do
self.field = helper.strip_tags(field)
end
end