Tag: load order

如何在gem中扩展ApplicationController?

我想我会想出一个灵活的方法来扩展Rails 3.x gem中的ApplicationController。 在我的gem的lib/my_namespace/my_controller.rb ,我有: class MyNamespace::MyController < ApplicationController before_filter :some_method after_filter :another_method def initialize # getting classname of the subclass to use for lookup of the associated model, etc. # and storing the model_class in an instance variable # … end # define :some_method, :another_method, etc. # … private attr_accessor :subclass_defined_during_initialize # etc. # […]