SlideShare a Scribd company logo
Rails Engines
!
@igmarin
Rails Engines
• Engines are stand-alone Rails application that can
be mounted inside of another application
• Controllers and Models are defined within
modules of the engine’s namespace
• architecting an app with engines forces you to
really think through your dependencies and
makes you isolate things from the get go
Big Plus
• Reduce errors from duplication
• Reusable code
Generate Rails Engine
we have a rails new plugin generator that will help us
$ rails plugin new awesome
creates a skeleton for
developing any kind of Rails
extension with ability to run
tests using dummy Rails
application
awesome
|-- Gemfile
|-- Gemfile.lock
|-- MIT-LICENSE
|-- README.rdoc
|-- Rakefile
|-- awesome.gemspec
|-- lib
| |-- awesome
| | `-- version.rb
| |-- awesome.rb
| `-- tasks
| `-- awesome_tasks.rake
`-- test
|-- awesome_test.rb
|-- dummy
$ rails plugin new awesome --full
--full tells that we want an
engine including app:
• An app directory tree
• An a config/routes.rb
awesome
|-- Gemfile
|-- Gemfile.lock
|-- MIT-LICENSE
|-- README.rdoc
|-- Rakefile
|-- app
| |-- assets
| |-- controllers
| |-- helpers
| |-- mailers
| |-- models
| `-- views
|-- awesome.gemspec
|-- bin
| `-- rails
|-- config
| `-- routes.rb
|-- lib
| |-- awesome
| | |-- engine.rb
| | `-- version.rb
| |-- awesome.rb
| `-- tasks
| `-- awesome_tasks.rake
`-- test
|-- awesome_test.rb
|-- dummy
lib/awesome/engine.rb
module Awesome
class Engine < ::Rails::Engine
end
end
$ rails plugin new awesome --mountable
namespace-isolated engine.
Same as full
• Asset manifest files (application.js and
application.css)
• A namespaced ApplicationController stub
• A namespaced ApplicationHelper stub
• A layout view template for the engine
awesome
|-- Gemfile
|-- Gemfile.lock
|-- MIT-LICENSE
|-- README.rdoc
|-- Rakefile
|-- app
| |-- assets
| |-- controllers
| |-- helpers
| |-- mailers
| |-- models
| `-- views
|-- awesome.gemspec
|-- bin
| `-- rails
|-- config
| `-- routes.rb
|-- lib
| |-- awesome
| | |-- engine.rb
| | `-- version.rb
| |-- awesome.rb
| `-- tasks
| `-- awesome_tasks.rake
`-- test
|-- awesome_test.rb
|-- dummy
lib/awesome/engine.rb
module Awesome
class Engine < ::Rails::Engine
isolate_namespace Awesome
end
end
test/dummy/config/routes.rb
Rails.application.routes.draw do
mount Awesome::Engine => "/awesome"
end
Route Helpers
awesome.root_url # /awesome
!
main_app.root_url # /
Generators
lib/generators/awesome/install_generator.rb
!
module Awesome
class InstallGenerator < Rails::Generators::Base
def install
run ‘bundle install’
route “mount Awesome::Engine => ‘/awesome’”
rake ‘awesome:install:migrations’
rake ‘db:migrate’
end
end
end
Popular Engines
• Devise —> Authentication
• Spree —> e-Commerce
• Forem —> Forum
• RailsAdmin —> Admin Interface
• Monologue —> Blogging
Resources
• Great Book: Multitenancy on Rails by Ryan Bigg
• https://www.youtube.com/watch?v=s3NJ15Svq8U
• http://guides.rubyonrails.org/engines.html
• http://tech.taskrabbit.com/blog/2014/02/11/rails-4-
engines/
• http://gaslight.co/blog/maintainable-and-scalable-
systems-with-rails-engines

More Related Content

PDF
React.js for Rails Developers
PDF
React on rails v6.1 at LA Ruby, November 2016
PPTX
The Rails Engine That Could
PPTX
Angular JS and Magento
KEY
Backbonification for dummies - Arrrrug 10/1/2012
PPTX
Architecture at PBS
PDF
React on rails v4
PDF
Apikit in studio
React.js for Rails Developers
React on rails v6.1 at LA Ruby, November 2016
The Rails Engine That Could
Angular JS and Magento
Backbonification for dummies - Arrrrug 10/1/2012
Architecture at PBS
React on rails v4
Apikit in studio

What's hot (20)

PPTX
Featfures of asp.net
PPT
Real World Rails Deployment
PPT
Creating the application
PPTX
October 2014 HUG : Apache Slider
PPTX
Reversengineering
PDF
Put a Button on It: Removing Barriers to Going Fast
PPT
Intro to SPA using JavaScript & ASP.NET
PPTX
Orchestration service v2
PPTX
PPTX
Sitecore 10 - ASP.NET Core Rendering with Docker and Sitecore 10
PPT
Ec2 for Startups - Ian Eure
PDF
"Serverless" express
PPT
Chef - managing yours servers with Code
PPT
Ember.js: Jump Start
PDF
Ansible Automation for Oracle RMAN / Apex Restores
PPTX
Sitecore sxa best practices and secrets 29th june 2021
PDF
Real Time with Rails 5
PDF
FITC - Exploring Art-Directed Responsive Images
PPT
Ruby Setup
PPT
Managing Servers with Chef
Featfures of asp.net
Real World Rails Deployment
Creating the application
October 2014 HUG : Apache Slider
Reversengineering
Put a Button on It: Removing Barriers to Going Fast
Intro to SPA using JavaScript & ASP.NET
Orchestration service v2
Sitecore 10 - ASP.NET Core Rendering with Docker and Sitecore 10
Ec2 for Startups - Ian Eure
"Serverless" express
Chef - managing yours servers with Code
Ember.js: Jump Start
Ansible Automation for Oracle RMAN / Apex Restores
Sitecore sxa best practices and secrets 29th june 2021
Real Time with Rails 5
FITC - Exploring Art-Directed Responsive Images
Ruby Setup
Managing Servers with Chef
Ad

Similar to Rails engines (20)

PPT
Rails engines
PPTX
Rails Engine :: modularize you app
PDF
A story about gemified engines
PPTX
Rails Engine | Modular application
PPTX
Rails Engine Patterns
PDF
Rails::Engine
PDF
Lightening a component based Rails architecture
PPT
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
KEY
How to set up and test a Rails 3 Engine
PDF
Rails engines in large apps
PDF
Rails Engines
PDF
Rails Engines - A presentation for the 22nd Athens Ruby Meetup
PPTX
The Rails Engine That Could - In Motion
PPTX
Rails engine
KEY
Plug it on!... with railties
ODP
DiUS Computing Lca Rails Final
PDF
feature flagging with rails engines v0.2
PDF
Ruby On Rails Basics
PPTX
Dev streams2
PDF
React with Ruby on Rails: Perfect Pair to Build Web Apps
Rails engines
Rails Engine :: modularize you app
A story about gemified engines
Rails Engine | Modular application
Rails Engine Patterns
Rails::Engine
Lightening a component based Rails architecture
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
How to set up and test a Rails 3 Engine
Rails engines in large apps
Rails Engines
Rails Engines - A presentation for the 22nd Athens Ruby Meetup
The Rails Engine That Could - In Motion
Rails engine
Plug it on!... with railties
DiUS Computing Lca Rails Final
feature flagging with rails engines v0.2
Ruby On Rails Basics
Dev streams2
React with Ruby on Rails: Perfect Pair to Build Web Apps
Ad

More from Ismael G Marín C (7)

PDF
PDF
TDD with Ruby
PDF
Rails Engine Español
PDF
Panel Magmaconf
PDF
Bootcamp Irapuato Welcome
PDF
Rubymotion primeros pasos
KEY
Presentacion minitest
TDD with Ruby
Rails Engine Español
Panel Magmaconf
Bootcamp Irapuato Welcome
Rubymotion primeros pasos
Presentacion minitest

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Getting Started with Data Integration: FME Form 101
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
August Patch Tuesday
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Tartificialntelligence_presentation.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Encapsulation theory and applications.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Reach Out and Touch Someone: Haptics and Empathic Computing
Getting Started with Data Integration: FME Form 101
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation_ Review paper, used for researhc scholars
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
NewMind AI Weekly Chronicles - August'25-Week II
August Patch Tuesday
Mobile App Security Testing_ A Comprehensive Guide.pdf
Unlocking AI with Model Context Protocol (MCP)
Programs and apps: productivity, graphics, security and other tools
Tartificialntelligence_presentation.pptx
Machine learning based COVID-19 study performance prediction
Heart disease approach using modified random forest and particle swarm optimi...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
A comparative study of natural language inference in Swahili using monolingua...
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

Rails engines

  • 2. Rails Engines • Engines are stand-alone Rails application that can be mounted inside of another application • Controllers and Models are defined within modules of the engine’s namespace • architecting an app with engines forces you to really think through your dependencies and makes you isolate things from the get go
  • 3. Big Plus • Reduce errors from duplication • Reusable code
  • 4. Generate Rails Engine we have a rails new plugin generator that will help us
  • 5. $ rails plugin new awesome creates a skeleton for developing any kind of Rails extension with ability to run tests using dummy Rails application awesome |-- Gemfile |-- Gemfile.lock |-- MIT-LICENSE |-- README.rdoc |-- Rakefile |-- awesome.gemspec |-- lib | |-- awesome | | `-- version.rb | |-- awesome.rb | `-- tasks | `-- awesome_tasks.rake `-- test |-- awesome_test.rb |-- dummy
  • 6. $ rails plugin new awesome --full --full tells that we want an engine including app: • An app directory tree • An a config/routes.rb awesome |-- Gemfile |-- Gemfile.lock |-- MIT-LICENSE |-- README.rdoc |-- Rakefile |-- app | |-- assets | |-- controllers | |-- helpers | |-- mailers | |-- models | `-- views |-- awesome.gemspec |-- bin | `-- rails |-- config | `-- routes.rb |-- lib | |-- awesome | | |-- engine.rb | | `-- version.rb | |-- awesome.rb | `-- tasks | `-- awesome_tasks.rake `-- test |-- awesome_test.rb |-- dummy
  • 8. $ rails plugin new awesome --mountable namespace-isolated engine. Same as full • Asset manifest files (application.js and application.css) • A namespaced ApplicationController stub • A namespaced ApplicationHelper stub • A layout view template for the engine awesome |-- Gemfile |-- Gemfile.lock |-- MIT-LICENSE |-- README.rdoc |-- Rakefile |-- app | |-- assets | |-- controllers | |-- helpers | |-- mailers | |-- models | `-- views |-- awesome.gemspec |-- bin | `-- rails |-- config | `-- routes.rb |-- lib | |-- awesome | | |-- engine.rb | | `-- version.rb | |-- awesome.rb | `-- tasks | `-- awesome_tasks.rake `-- test |-- awesome_test.rb |-- dummy
  • 9. lib/awesome/engine.rb module Awesome class Engine < ::Rails::Engine isolate_namespace Awesome end end test/dummy/config/routes.rb Rails.application.routes.draw do mount Awesome::Engine => "/awesome" end
  • 10. Route Helpers awesome.root_url # /awesome ! main_app.root_url # /
  • 11. Generators lib/generators/awesome/install_generator.rb ! module Awesome class InstallGenerator < Rails::Generators::Base def install run ‘bundle install’ route “mount Awesome::Engine => ‘/awesome’” rake ‘awesome:install:migrations’ rake ‘db:migrate’ end end end
  • 12. Popular Engines • Devise —> Authentication • Spree —> e-Commerce • Forem —> Forum • RailsAdmin —> Admin Interface • Monologue —> Blogging
  • 13. Resources • Great Book: Multitenancy on Rails by Ryan Bigg • https://www.youtube.com/watch?v=s3NJ15Svq8U • http://guides.rubyonrails.org/engines.html • http://tech.taskrabbit.com/blog/2014/02/11/rails-4- engines/ • http://gaslight.co/blog/maintainable-and-scalable- systems-with-rails-engines