. , , , . .
ActionController, ApplicationController , :
class ApplicationController < ActionController::Base
def self.before_filter_with_logging(*arguments, &block)
filters, conditions =
ActionController::Filters::FilterChain.extract_options(arguments, &block)
filter_method_names = filters.map { |fm| fm.to_s }.join(', ')
logger.info "Setting up before_filter to #{filter_method_names}"
filter_methods_with_logging =
filters.map { |fm| (fm.to_s + "_with_logging").to_sym }
filters.each { |fm|
define_method( (fm.to_s + "_with_logging").to_sym ) { |*args|
logger.info "Calling before_filter #{fm}"
if args.empty?
send fm
else
send fm, args
end
}
}
before_filter_without_logging(filter_methods_with_logging, &block)
end
class << self
alias_method_chain :before_filter, :logging
end
before_filter :your_first_before_filter
Tomáš Pospíšek