Permalink
Browse files

add boilerplate so can get helpers out of ApplicationController

  • Loading branch information...
rwilcox committed Oct 20, 2011
1 parent 1a82c8c commit 81a8604a096110c9a95cc35e25e6b2ff32347224
Showing with 33 additions and 0 deletions.
  1. +33 −0 lib/application_controller.rb
@@ -0,0 +1,33 @@
module DelegatePresenter::ApplicationController
# Provide access to helper methods from outside controllers and views,
# such as in Presenter objects. Rails provides ActionController::Base.helpers,
# but this does not include any of our application helpers.
def all_helpers
@all_helpers_proxy ||= begin
# Start with just the rails helpers. This is the same method used
# by ActionController::Base.helpers
proxy = ActionView::Base.new.extend(_helpers)
# url_for depends on _routes method being defined
proxy.instance_eval do
def _routes
Rails.application.routes
end
end
# Import all named path methods
proxy.extend(Rails.application.routes.named_routes.module)
# Load all our application helpers to extend
modules_for_helpers([:all]).each do |mod|
proxy.extend(mod)
end
proxy
end
end
end
class ApplicationController
extend DelegatePresenter::ApplicationController
end

0 comments on commit 81a8604

Please sign in to comment.