原文:http://api.rubyonrails.org/classes/Rails/Railtie.html
# lib/my_gem/railtie.rb module MyGem class Railtie < Rails::Railtie end end # lib/my_gem.rb require ‘my_gem/railtie‘ if defined?(Rails)
class MyRailtie < Rails::Railtie initializer "my_railtie.configure_rails_initialization" do # some initialization behavior end end
class MyRailtie < Rails::Railtie initializer "my_railtie.configure_rails_initialization" do |app| app.middleware.use MyRailtie::Middleware end end
:before
和 :after 作为 initializer 的 参数。
class MyRailtie < Rails::Railtie # 定制 ORM config.app_generators.orm :my_railtie_orm # Add a to_prepare block which is executed once in production # and before each request in development config.to_prepare do MyRailtie.setup! end end
class MyRailtie < Rails::Railtie rake_tasks do load "path/to/my_railtie.tasks" end end
class MyRailtie < Rails::Railtie generators do require "path/to/my_railtie_generator" end end
原文:http://www.cnblogs.com/fanxiaopeng/p/4455974.html