Skip to content

Instantly share code, notes, and snippets.

@timlinquist
Created April 14, 2011 23:08
Show Gist options
  • Select an option

  • Save timlinquist/920791 to your computer and use it in GitHub Desktop.

Select an option

Save timlinquist/920791 to your computer and use it in GitHub Desktop.
A beautiful hack to extend Rails to allow custom actions for a controller instance & helpers for thew view.
def self.extended(controller)
controller.extend(ControllerMethods)
controller._helpers.module_eval { include HelperMethods }
existing_actions = controller.action_methods + ControllerMethods.public_instance_methods(true)
controller.class.class_eval do
cattr_accessor :actions_to_use
def self.override_action_methods(actions=[])
self.actions_to_use = actions
end
def self.action_methods
self.actions_to_use || @action_methods
end
end
controller.class.override_action_methods(existing_actions)
end
Use:
In before_filter on controller:
load File.join(file_root,'content_methods.rb') unless Object.const_defined?(@client_domain.namespace)
self.extend(@client_domain.namespace.constantize)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment