我想将宏添加到控制器,如活动记录:has_many
class ApplicationController < ActionController::Base
macro_to_define_methods :parameters => :here
end
我怎样才能做到这一点?
谢谢。
答案 0 :(得分:1)
module ControllerExtensions
def do_something(options)
# do something with options here, e.g. define_method
end
end
ActionController::Base.extend(ControllerExtensions)
class ApplicationController < ActionController::Base
do_something :parameters => :here
end