SlideShare a Scribd company logo
1 of 21
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

Rails Engine Patterns
Rails Engine PatternsRails Engine Patterns
Rails Engine PatternsAndy Maleh
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsDeepak Chandani
 
Railsguide
RailsguideRailsguide
Railsguidelanlau
 
Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJSBlake Newman
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with LaravelAbuzer Firdousi
 
RoR 101: Session 5
RoR 101: Session 5RoR 101: Session 5
RoR 101: Session 5Rory Gianni
 
Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Fwdays
 
Apikit from command line
Apikit from command lineApikit from command line
Apikit from command linefedefortin
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravelConfiz
 
Be Happy With Ruby on Rails - Ecosystem
Be Happy With Ruby on Rails - EcosystemBe Happy With Ruby on Rails - Ecosystem
Be Happy With Ruby on Rails - EcosystemLucas Renan
 
RoR 101: Session 3
RoR 101: Session 3RoR 101: Session 3
RoR 101: Session 3Rory Gianni
 
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIsCustom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIsAkhil Mittal
 
Rest api titouan benoit
Rest api   titouan benoitRest api   titouan benoit
Rest api titouan benoitTitouan BENOIT
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2Rory Gianni
 
Rack is Spectacular
Rack is SpectacularRack is Spectacular
Rack is SpectacularBryce Kerley
 
Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuLucas Renan
 

What's hot (20)

Rails Engine Patterns
Rails Engine PatternsRails Engine Patterns
Rails Engine Patterns
 
Rails engines
Rails enginesRails engines
Rails engines
 
Rails 3
Rails 3Rails 3
Rails 3
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 Components
 
Railsguide
RailsguideRailsguide
Railsguide
 
Cocoa on-rails-3rd
Cocoa on-rails-3rdCocoa on-rails-3rd
Cocoa on-rails-3rd
 
Rack
RackRack
Rack
 
Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
 
RoR 101: Session 5
RoR 101: Session 5RoR 101: Session 5
RoR 101: Session 5
 
Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)
 
Apikit from command line
Apikit from command lineApikit from command line
Apikit from command line
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 
Be Happy With Ruby on Rails - Ecosystem
Be Happy With Ruby on Rails - EcosystemBe Happy With Ruby on Rails - Ecosystem
Be Happy With Ruby on Rails - Ecosystem
 
RoR 101: Session 3
RoR 101: Session 3RoR 101: Session 3
RoR 101: Session 3
 
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIsCustom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
 
Rest api titouan benoit
Rest api   titouan benoitRest api   titouan benoit
Rest api titouan benoit
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
Rack is Spectacular
Rack is SpectacularRack is Spectacular
Rack is Spectacular
 
Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
 

Similar to How to set up and test a Rails 3 Engine

Ruby on Rails introduction
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction Tran Hung
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortegaarman o
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011Lance Ball
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011Fabio Akita
 
09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do railsDNAD
 
Rails request & middlewares
Rails request & middlewaresRails request & middlewares
Rails request & middlewaresSantosh Wadghule
 
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012Andy Maleh
 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...Matt Gauger
 
Rails in the bowels
Rails in the bowelsRails in the bowels
Rails in the bowelsCreditas
 
A story about gemified engines
A story about gemified enginesA story about gemified engines
A story about gemified enginesmglrnm
 

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

Railties
RailtiesRailties
Railties
 
Rails engine
Rails engineRails engine
Rails engine
 
rails.html
rails.htmlrails.html
rails.html
 
rails.html
rails.htmlrails.html
rails.html
 
Ruby on Rails introduction
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
Create a new project in ROR
Create a new project in RORCreate a new project in ROR
Create a new project in ROR
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011
 
09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails
 
Rail3 intro 29th_sep_surendran
Rail3 intro 29th_sep_surendranRail3 intro 29th_sep_surendran
Rail3 intro 29th_sep_surendran
 
Rails request & middlewares
Rails request & middlewaresRails request & middlewares
Rails request & middlewares
 
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
 
TorqueBox
TorqueBoxTorqueBox
TorqueBox
 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
 
Rails in the bowels
Rails in the bowelsRails in the bowels
Rails in the bowels
 
Intro lift
Intro liftIntro lift
Intro lift
 
Service Oriented Applications
Service Oriented ApplicationsService Oriented Applications
Service Oriented Applications
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
 
A story about gemified engines
A story about gemified enginesA story about gemified engines
A story about gemified engines
 

Recently uploaded

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 

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

Editor's Notes