Differences between railties and engines in Ruby On Rails 3

Rails::Engine inherits all the functionality from Rails::Railtie and adds some more (Engine < Railtie source code [docs in the source are pretty good]).

Basically, railtie (== your class that inherits from Rails::Railtie) gives you all you need to interact with Rails app processes.
And engine (== your class that inherits from Rails::Engine) is railtie +

  • some initializers set (with help of initializer method): makes your engine's Rails app-like folder structure loadable into the real app, so that

    engine will automatically load app/models, app/controllers, app/helpers into your real app, load routes from config/routes.rb, load locales from config/locales/*, and load tasks from lib/tasks/*.

    You can see initializers set with this code:

    require 'rails/all'
    Rails::Railtie.initializers.map(&:name) #=> []  
    Rails::Engine.initializers.map(&:name)  #=> [:set_load_path, :set_autoload_paths, :add_routing_paths, :add_locales, :add_view_paths, :load_environment_config, :append_assets_path, :prepend_helpers_path, :load_config_initializers, :engines_blank_point]
    
  • some convenience methods, such as isolate_namespace.


Railtie can probably do what you describe, but it may be more desirable to use an engine. The engine can have its own configuration and also acts like a Rails application, since it allows you to include the /app directory with controllers, views and models in the same manner as a regular Rails app.

Read this blog for more info