Skip to content

Instantly share code, notes, and snippets.

@hmcfletch
Created January 1, 2012 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmcfletch/1548627 to your computer and use it in GitHub Desktop.
Save hmcfletch/1548627 to your computer and use it in GitHub Desktop.
Automatic Observer Registration
module AppName
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [:password]
config.assets.enabled = true
config.assets.version = '1.0'
# registers any file in the app/observers directory as an observer
observers = [] # Register all observers in the observers folder.
pattern = File.join(Rails.application.config.root, 'app', 'observers', '**', '*.rb')
Dir.glob(pattern).each { |f| observers << File.basename(f, '.rb').to_sym }
config.active_record.observers = observers
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment