class Rails::Railtie
Be sure to look at the documentation of those specific classes for more information.
described here can be used in all three.
And since Rails::Application and Rails::Plugin are engines, the same configuration
A Rails::Engine is nothing more than a Railtie with some initializers already set.
== Application, Plugin and Engine
end
end
require “path/to/my_railtie_generator”
generators do
class MyRailtie < Rails::Railtie
will load them during normal generators lookup:
your generators at a different location, you can specify in your Railtie a block which
By default, Rails load generators from your load path. However, if you want to place
end
end
load “path/to/my_railtie.tasks”
rake_tasks do
class MyRailtie < Rails::Railtie
rake tasks:
If your railtie has rake tasks, you can tell Rails to load them through the method
== Loading rake tasks and generators
end
end
MyRailtie.setup!
config.to_prepare do
# and before which request in development
# Add a to_prepare block which is executed once in production
config.app_generators.orm :my_railtie_orm
# Customize the ORM
class MyRailtie < Rails::Railtie
shared by all railties and the application:
Inside the Railtie class, you can access a config object which contains configuration
== Configuration
you want to couple it with a specific step in the initialization process.
Finally, you can also pass :before and :after as option to initializer, in case
end
end
app.middleware.use MyRailtie::Middleware
initializer “my_railtie.configure_rails_initialization” do |app|
class MyRailtie < Rails::Railtie
need to access some application specific configuration, like middleware:
If specified, the block can also receive the application object, in case you
end
end
# some initialization behavior
initializer “my_railtie.configure_rails_initialization” do
class MyRailtie < Rails::Railtie
to create an initializer block:
To add an initialization step from your Railtie to Rails boot process, you just need
== Initializers
end
end
class Railtie < Rails::Railtie
module MyGem
require ‘rails’
require ‘my_gem’
# lib/my_gem/railtie.rb
* Require your own gem as well as rails in this file:
end
end
class Railtie < Rails::Railtie
module MyGem
# lib/my_gem/railtie.rb
Rails::Railtie and is namespaced to your gem:
* Create a file (say, lib/my_gem/railtie.rb) which contains class Railtie inheriting from
it for a gem that can be used with or without Rails:
You can do this however you wish, but here is an example if you want to provide
during boot time of the Rails stack.
Railtie that has your extension name and making sure that this gets loaded
Implementing Railtie in your Rails extension is done by creating a class
== Creating your Railtie
* adding rake tasks into rails
* setting up a subscriber to the Rails ActiveSupport::Notifications
* adding Rails config.* keys to the environment
* configuring a Rails framework or the Application, like setting a generator
* creating initializers
plugin:
For example, the following would need you to implement Railtie in your
or after boot, then Railtie is what you need to do that interaction.
Railtie, but if you need to interact with the Rails framework during
Developing a Rails extension does not require any implementation of
Rails absent of any Active Record hook, allowing any other ORM framework to hook in.
them is responsible to set their own initialization. This makes, for example,
Action View, Active Record and Active Resource) are all Railties, so each of
Every major component of Rails (Action Mailer, Action Controller,
Rails and/or modify the initialization process.
Railtie is the core of the Rails Framework and provides several hooks to extend
def abstract_railtie?
def abstract_railtie? ABSTRACT_RAILTIES.include?(name) end
def console(&blk)
def console(&blk) @load_console ||= [] @load_console << blk if blk @load_console end
def eager_load!
def eager_load! end
def generators(&blk)
def generators(&blk) @generators ||= [] @generators << blk if blk @generators end
def inherited(base)
def inherited(base) unless base.abstract_railtie? base.send(:include, self::Configurable) subclasses << base end end
def load_console
def load_console self.class.console.each(&:call) end
def load_generators
def load_generators self.class.generators.each(&:call) end
def load_tasks
def load_tasks self.class.rake_tasks.each(&:call) end
def log_subscriber(*)
def log_subscriber(*) ActiveSupport::Deprecation.warn "log_subscriber is deprecated and has no effect", caller end
def railtie_name(*)
def railtie_name(*) ActiveSupport::Deprecation.warn "railtie_name is deprecated and has no effect", caller end
def rake_tasks(&blk)
def rake_tasks(&blk) @rake_tasks ||= [] @rake_tasks << blk if blk @rake_tasks end
def subclasses
def subclasses @subclasses ||= [] end