SlideShare a Scribd company logo
HOW TO SETUP AND
TEST RAILS 3 ENGINES.




              Nicholas Faiz,
   Tree Falling In The Woods, Pty Ltd.
INTRO

A quick introduction to Engines in Rails 3, including
a demo of how to set one up and test it.

Background: I've been working on a Rails 3 engine
project since February or so. It might help if I share
what I've encountered so far.

Rails 3 Engines are new. Rails 3 RC 2 only released a
few days ago.
INTRO 2


Finding information on how to set up an Engine in
Rails 3 has been difficult. Useful blogs: http://
www.themodestrubyist.com - by Jordan West. 4 posts
about engines.

Cesario: http://www.dev-fr.com/archives/
2010/04/07/rails-3-railties-and-engines/
STORY OF ENGINES SO
         FAR




Engines before Rails 2.3
                             Engines Incorporated 2.3




         Engines revamped in Rails 3
STORY OF ENGINES ... 2

How were they revamped in Rails 3? Merb influence
of decoupling.

2009 Merb merged with Rails. Merb influence r.e.
decoupled dependencies! e.g. Should be able to use
whichever ORM in your MVC.

In Rails 3 engines revamped, now inherit from
Rails::Railtie (See the Merb influence)
WHAT ARE RAILTIES?

Railties are a central concept to Rails 3. They
decouple components from each other.

See http://railsapi.com/doc/rails-v3.0.0.beta.3/
classes/Rails/Railtie.html

All major aspects of the Rails Framework are now
assembled into a larger system via a collection of
Railties.
WHAT ARE RAILTIES? 2


ActionController::Railtie < Rails::Railtie,
ActionView::Railtie < Rails::Railtie, etc.

Railties carry initializers, letting you configure how a
Rails application is bootstrapped.’

initializer "configure something" {|app|
config.something()}
WHAT ARE ENGINES?

Rails 3: Engines *are* Railties, well, subclasses of
them.

Rails::Engine < Rails::Railties

In fact, every Rails application *is* an engine, well, a
subclass ...

Rails::Application < Rails::Engine
WHAT ARE ENGINES?


Only touching upon functionality in this
presentation.

Hosting applications can use them, or override them
if they want to change things.

Most known Rails 3 engine at the moment - Devise:
http://github.com/plataformatec/devise
CONFIGURE, BUNDLE,
       TEST
Engines are a bit more than just a Rails application,
though. More to it than the API. You have to know
how to configure, bundle, and test it.

You bundle a Rails engine, in its own gem, to reuse
within another Rails application.

First understand how an engine is accessed and used
by a Rails application.

Standard Rails app. paths available in the engine ...
ENGINE PATHS
class MyEngine < Rails::Engine
 paths.app           = "app"
 paths.app.controllers = "app/controllers"
 paths.app.helpers       = "app/helpers"
 paths.app.models         = "app/models"
 paths.app.metals        = "app/metal"
 paths.app.views         = "app/views"
 paths.lib         = "lib"
 paths.lib.tasks      = "lib/tasks"
 paths.config          = "config"
 paths.config.initializers = "config/initializers"
 paths.config.locales = "config/locales"
 paths.config.routes      = "config/routes.rb"
end
ENGINES INSIDE THE
      HOST APP.


All of this information is addressable via the Rails
object.

ruby-1.8.7-p299 > Rails.application.railties.engines

Holds an array of engine objects.
PATHS IN RAILS
                           ENGINES

    rails console

    ruby-1.8.7-p299 > e = Rails.application.railties.engines.last

    ruby-1.8.7-p299 > e.config.paths.app
a    => #<Rails::Paths::Path:0x103bf7058 @eager_load=true, @root=#<Rails::Paths::Root:
    0x103c02958 @all_paths=[#<Rails::Paths::Path:0x103bf7058 ...>, …, @paths=["app"]>

    ruby-1.8.7-p299 > e.class.name
     => "InklingContent::Engine" #helps to give your Railtie an informative namespace
FINDING AN ENGINE
      BLUEPRINT
I began working on my own engines and made
headway in some areas but not others.

I decided that I wanted a simple blueprint of how an
engine should look.

Because engines are new, there aren't established
practices for setting them up and testing them. I've
come up with my own, which seem like common
sense, but took some thought.
TOMMY THE RAILS 3
      ENGINE!


So I created Tommy, a
simple application with
a picture of Tommy the
Tank engine repeating a
message held in sqlite.
HOW IS SOMETHING SO
  SIMPLE HELPFUL?

Demonstrates some basic concepts. Some projects
would actually copy their static files - javascripts,
partials, etc. - *over* the hosting application. (e.g.
BrowserCMS), in the Rails 2.x days.

I needed to prove how sharing assets was done
without this intrusion in Rails 3.
IN DEMO LOOK FOR ...

The Railties file (the engine).

Generators for migrations.

How to share static assets (like images, stylesheets,
javascript files, etc.), from the engine into the host
engine.

How to share rake tasks.

How to configure rspec and cucumber in an engine.
TOMMY THE RAILS 3
    ENGINE DEMO




http://github.com/biv/tommy
SUMMATION


An engine can't be used without a functioning Rails
app.. I find it easiest to nest a Rails app beneath the
top directory.

Tests for the engine can be created at the top level
directory of the engine, but symlinked into the test
app..
SUMMATION 2




Rails 3 engines are new. I haven’t heard many stories,
yet, about how they perform in production settings.
CONTACT ME TO
     DISCUSS ENGINES

I’m basing a lot of work in 2010/2011 on the Engine
structure. I’m happy to discuss them:



biv/brain_in_vat on #roro freenode

http://twitter.com/nicholasf

More Related Content

What's hot (20)

PPTX
Rails Engine Patterns
Andy Maleh
 
PPT
Rails engines
Josh Schramm
 
PPT
Rails 3
Iain Hecker
 
PPTX
Creating your own framework on top of Symfony2 Components
Deepak Chandani
 
PDF
Railsguide
lanlau
 
KEY
Cocoa on-rails-3rd
Xiaochun Shen
 
PDF
Laravel Restful API and AngularJS
Blake Newman
 
PPT
Web service with Laravel
Abuzer Firdousi
 
PDF
RoR 101: Session 5
Rory Gianni
 
PDF
Ruby w/o Rails (Олександр Сімонов)
Fwdays
 
PDF
Apikit from command line
fedefortin
 
PDF
Web services with laravel
Confiz
 
PDF
Be Happy With Ruby on Rails - Ecosystem
Lucas Renan
 
PDF
RoR 101: Session 3
Rory Gianni
 
PDF
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Akhil Mittal
 
PDF
Rest api titouan benoit
Titouan BENOIT
 
PDF
RoR 101: Session 2
Rory Gianni
 
KEY
Rack is Spectacular
Bryce Kerley
 
PDF
Be happy with Ruby on Rails - CEUNSP Itu
Lucas Renan
 
Rails Engine Patterns
Andy Maleh
 
Rails engines
Josh Schramm
 
Rails 3
Iain Hecker
 
Creating your own framework on top of Symfony2 Components
Deepak Chandani
 
Railsguide
lanlau
 
Cocoa on-rails-3rd
Xiaochun Shen
 
Laravel Restful API and AngularJS
Blake Newman
 
Web service with Laravel
Abuzer Firdousi
 
RoR 101: Session 5
Rory Gianni
 
Ruby w/o Rails (Олександр Сімонов)
Fwdays
 
Apikit from command line
fedefortin
 
Web services with laravel
Confiz
 
Be Happy With Ruby on Rails - Ecosystem
Lucas Renan
 
RoR 101: Session 3
Rory Gianni
 
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Akhil Mittal
 
Rest api titouan benoit
Titouan BENOIT
 
RoR 101: Session 2
Rory Gianni
 
Rack is Spectacular
Bryce Kerley
 
Be happy with Ruby on Rails - CEUNSP Itu
Lucas Renan
 

Similar to How to set up and test a Rails 3 Engine (20)

PDF
Railties
Skills Matter
 
PPTX
Rails engine
Jyaasa Technologies
 
PDF
rails.html
tutorialsruby
 
PDF
rails.html
tutorialsruby
 
PPT
Ruby on Rails introduction
Tran Hung
 
PDF
Introduction to Rails - presented by Arman Ortega
arman o
 
KEY
TorqueBox - Ruby Hoedown 2011
Lance Ball
 
PDF
Create a new project in ROR
akankshita satapathy
 
PDF
.NET Architects Day - DNAD 2011
Fabio Akita
 
PDF
09 - Fábio Akita - Além do rails
DNAD
 
PPT
Rail3 intro 29th_sep_surendran
SPRITLE SOFTWARE PRIVATE LIMIT ED
 
PDF
Rails request & middlewares
Santosh Wadghule
 
PPT
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
Andy Maleh
 
PDF
TorqueBox
bobmcwhirter
 
KEY
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
Matt Gauger
 
PPTX
Rails in the bowels
Creditas
 
PPT
Intro lift
Knoldus Inc.
 
KEY
Service Oriented Applications
Michael Bensoussan
 
PDF
Intro to Rack
Rubyc Slides
 
PDF
A story about gemified engines
mglrnm
 
Railties
Skills Matter
 
Rails engine
Jyaasa Technologies
 
rails.html
tutorialsruby
 
rails.html
tutorialsruby
 
Ruby on Rails introduction
Tran Hung
 
Introduction to Rails - presented by Arman Ortega
arman o
 
TorqueBox - Ruby Hoedown 2011
Lance Ball
 
Create a new project in ROR
akankshita satapathy
 
.NET Architects Day - DNAD 2011
Fabio Akita
 
09 - Fábio Akita - Além do rails
DNAD
 
Rail3 intro 29th_sep_surendran
SPRITLE SOFTWARE PRIVATE LIMIT ED
 
Rails request & middlewares
Santosh Wadghule
 
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
Andy Maleh
 
TorqueBox
bobmcwhirter
 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
Matt Gauger
 
Rails in the bowels
Creditas
 
Intro lift
Knoldus Inc.
 
Service Oriented Applications
Michael Bensoussan
 
Intro to Rack
Rubyc Slides
 
A story about gemified engines
mglrnm
 
Ad

Recently uploaded (20)

PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
July Patch Tuesday
Ivanti
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Ad

How to set up and test a Rails 3 Engine

  • 1. HOW TO SETUP AND TEST RAILS 3 ENGINES. Nicholas Faiz, Tree Falling In The Woods, Pty Ltd.
  • 2. INTRO A quick introduction to Engines in Rails 3, including a demo of how to set one up and test it. Background: I've been working on a Rails 3 engine project since February or so. It might help if I share what I've encountered so far. Rails 3 Engines are new. Rails 3 RC 2 only released a few days ago.
  • 3. INTRO 2 Finding information on how to set up an Engine in Rails 3 has been difficult. Useful blogs: http:// www.themodestrubyist.com - by Jordan West. 4 posts about engines. Cesario: http://www.dev-fr.com/archives/ 2010/04/07/rails-3-railties-and-engines/
  • 4. STORY OF ENGINES SO FAR Engines before Rails 2.3 Engines Incorporated 2.3 Engines revamped in Rails 3
  • 5. STORY OF ENGINES ... 2 How were they revamped in Rails 3? Merb influence of decoupling. 2009 Merb merged with Rails. Merb influence r.e. decoupled dependencies! e.g. Should be able to use whichever ORM in your MVC. In Rails 3 engines revamped, now inherit from Rails::Railtie (See the Merb influence)
  • 6. WHAT ARE RAILTIES? Railties are a central concept to Rails 3. They decouple components from each other. See http://railsapi.com/doc/rails-v3.0.0.beta.3/ classes/Rails/Railtie.html All major aspects of the Rails Framework are now assembled into a larger system via a collection of Railties.
  • 7. WHAT ARE RAILTIES? 2 ActionController::Railtie < Rails::Railtie, ActionView::Railtie < Rails::Railtie, etc. Railties carry initializers, letting you configure how a Rails application is bootstrapped.’ initializer "configure something" {|app| config.something()}
  • 8. WHAT ARE ENGINES? Rails 3: Engines *are* Railties, well, subclasses of them. Rails::Engine < Rails::Railties In fact, every Rails application *is* an engine, well, a subclass ... Rails::Application < Rails::Engine
  • 9. WHAT ARE ENGINES? Only touching upon functionality in this presentation. Hosting applications can use them, or override them if they want to change things. Most known Rails 3 engine at the moment - Devise: http://github.com/plataformatec/devise
  • 10. CONFIGURE, BUNDLE, TEST Engines are a bit more than just a Rails application, though. More to it than the API. You have to know how to configure, bundle, and test it. You bundle a Rails engine, in its own gem, to reuse within another Rails application. First understand how an engine is accessed and used by a Rails application. Standard Rails app. paths available in the engine ...
  • 11. ENGINE PATHS class MyEngine < Rails::Engine paths.app = "app" paths.app.controllers = "app/controllers" paths.app.helpers = "app/helpers" paths.app.models = "app/models" paths.app.metals = "app/metal" paths.app.views = "app/views" paths.lib = "lib" paths.lib.tasks = "lib/tasks" paths.config = "config" paths.config.initializers = "config/initializers" paths.config.locales = "config/locales" paths.config.routes = "config/routes.rb" end
  • 12. ENGINES INSIDE THE HOST APP. All of this information is addressable via the Rails object. ruby-1.8.7-p299 > Rails.application.railties.engines Holds an array of engine objects.
  • 13. PATHS IN RAILS ENGINES rails console ruby-1.8.7-p299 > e = Rails.application.railties.engines.last ruby-1.8.7-p299 > e.config.paths.app a => #<Rails::Paths::Path:0x103bf7058 @eager_load=true, @root=#<Rails::Paths::Root: 0x103c02958 @all_paths=[#<Rails::Paths::Path:0x103bf7058 ...>, …, @paths=["app"]> ruby-1.8.7-p299 > e.class.name => "InklingContent::Engine" #helps to give your Railtie an informative namespace
  • 14. FINDING AN ENGINE BLUEPRINT I began working on my own engines and made headway in some areas but not others. I decided that I wanted a simple blueprint of how an engine should look. Because engines are new, there aren't established practices for setting them up and testing them. I've come up with my own, which seem like common sense, but took some thought.
  • 15. TOMMY THE RAILS 3 ENGINE! So I created Tommy, a simple application with a picture of Tommy the Tank engine repeating a message held in sqlite.
  • 16. HOW IS SOMETHING SO SIMPLE HELPFUL? Demonstrates some basic concepts. Some projects would actually copy their static files - javascripts, partials, etc. - *over* the hosting application. (e.g. BrowserCMS), in the Rails 2.x days. I needed to prove how sharing assets was done without this intrusion in Rails 3.
  • 17. IN DEMO LOOK FOR ... The Railties file (the engine). Generators for migrations. How to share static assets (like images, stylesheets, javascript files, etc.), from the engine into the host engine. How to share rake tasks. How to configure rspec and cucumber in an engine.
  • 18. TOMMY THE RAILS 3 ENGINE DEMO http://github.com/biv/tommy
  • 19. SUMMATION An engine can't be used without a functioning Rails app.. I find it easiest to nest a Rails app beneath the top directory. Tests for the engine can be created at the top level directory of the engine, but symlinked into the test app..
  • 20. SUMMATION 2 Rails 3 engines are new. I haven’t heard many stories, yet, about how they perform in production settings.
  • 21. CONTACT ME TO DISCUSS ENGINES I’m basing a lot of work in 2010/2011 on the Engine structure. I’m happy to discuss them: biv/brain_in_vat on #roro freenode http://twitter.com/nicholasf