Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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