💎 Ruby on Rails
Advanced
What are Rails engines and how are they used?
Answer
A Rails engine is a self-contained mini-application that can be mounted inside a Rails app, providing isolated controllers, models, views, migrations, and routes. rails plugin new my_engine --mountable creates a mountable engine. Mount with: mount MyEngine::Engine, at: '/my_engine' in the host app's routes. Engines are used to package reusable functionality — Devise, ActiveAdmin, Spree Commerce, and Sidekiq's web UI are all engines. Namespacing prevents class name collisions. Shared tables are handled via isolate_namespace. Engines can have their own migrations, which the host app runs separately.
Previous
What is query optimization with explain in Rails?
Next
What is the difference between class methods and instance methods in ActiveRecord?
More Ruby on Rails Questions
View all →- Advanced What is metaprogramming in Ruby/Rails and give examples?
- Advanced What is the difference between include, extend, and prepend in Ruby?
- Advanced How does Rails handle database connection pooling?
- Advanced What is Rack and how does Rails relate to it?
- Advanced What is query optimization with explain in Rails?