简体   繁体   中英

How to add macro for controller?

I want to add macro to controller like active record :has_many

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

How can I achieve this?

Thank You.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM