如何为控制器添加宏?

时间:2012-01-27 07:00:47

标签: ruby-on-rails ruby ruby-on-rails-3 macros

我想将宏添加到控制器,如活动记录:has_many

class ApplicationController < ActionController::Base
  macro_to_define_methods :parameters => :here
end

我怎样才能做到这一点?

谢谢。

1 个答案:

答案 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