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
Ad

More Related Content

What's hot (20)

Rails Engine Patterns
Rails Engine PatternsRails Engine Patterns
Rails Engine Patterns
Andy Maleh
 
Rails engines
Rails enginesRails engines
Rails engines
Josh Schramm
 
Rails 3
Rails 3Rails 3
Rails 3
Iain Hecker
 
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
Deepak Chandani
 
Railsguide
RailsguideRailsguide
Railsguide
lanlau
 
Cocoa on-rails-3rd
Cocoa on-rails-3rdCocoa on-rails-3rd
Cocoa on-rails-3rd
Xiaochun Shen
 
Rack
RackRack
Rack
Revath S Kumar
 
Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
Blake Newman
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
Abuzer Firdousi
 
RoR 101: Session 5
RoR 101: Session 5RoR 101: Session 5
RoR 101: Session 5
Rory 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 line
fedefortin
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
Confiz
 
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
Lucas Renan
 
RoR 101: Session 3
RoR 101: Session 3RoR 101: Session 3
RoR 101: Session 3
Rory 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 APIs
Akhil Mittal
 
Rest api titouan benoit
Rest api   titouan benoitRest api   titouan benoit
Rest api titouan benoit
Titouan BENOIT
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
Rory Gianni
 
Rack is Spectacular
Rack is SpectacularRack is Spectacular
Rack is Spectacular
Bryce 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 Itu
Lucas Renan
 
Rails Engine Patterns
Rails Engine PatternsRails Engine Patterns
Rails Engine Patterns
Andy 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 Components
Deepak Chandani
 
Railsguide
RailsguideRailsguide
Railsguide
lanlau
 
Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
Blake Newman
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
Abuzer Firdousi
 
RoR 101: Session 5
RoR 101: Session 5RoR 101: Session 5
RoR 101: Session 5
Rory 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 line
fedefortin
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
Confiz
 
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
Lucas Renan
 
RoR 101: Session 3
RoR 101: Session 3RoR 101: Session 3
RoR 101: Session 3
Rory 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 APIs
Akhil Mittal
 
Rest api titouan benoit
Rest api   titouan benoitRest api   titouan benoit
Rest api titouan benoit
Titouan BENOIT
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
Rory Gianni
 
Rack is Spectacular
Rack is SpectacularRack is Spectacular
Rack is Spectacular
Bryce 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 Itu
Lucas Renan
 

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

Railties
RailtiesRailties
Railties
Skills Matter
 
Rails engine
Rails engineRails engine
Rails engine
Jyaasa Technologies
 
rails.html
rails.htmlrails.html
rails.html
tutorialsruby
 
rails.html
rails.htmlrails.html
rails.html
tutorialsruby
 
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 Ortega
arman o
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
Lance Ball
 
Create a new project in ROR
Create a new project in RORCreate a new project in ROR
Create a new project in ROR
akankshita satapathy
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011
Fabio 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 rails
DNAD
 
Rail3 intro 29th_sep_surendran
Rail3 intro 29th_sep_surendranRail3 intro 29th_sep_surendran
Rail3 intro 29th_sep_surendran
SPRITLE SOFTWARE PRIVATE LIMIT ED
 
Rails request & middlewares
Rails request & middlewaresRails request & middlewares
Rails request & middlewares
Santosh 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, 2012
Andy Maleh
 
TorqueBox
TorqueBoxTorqueBox
TorqueBox
bobmcwhirter
 
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 bowels
Creditas
 
Intro lift
Intro liftIntro lift
Intro lift
Knoldus Inc.
 
Service Oriented Applications
Service Oriented ApplicationsService Oriented Applications
Service Oriented Applications
Michael Bensoussan
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
Rubyc Slides
 
A story about gemified engines
A story about gemified enginesA story about gemified engines
A story about gemified engines
mglrnm
 
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 Ortega
arman o
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
Lance Ball
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011
Fabio 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 rails
DNAD
 
Rails request & middlewares
Rails request & middlewaresRails request & middlewares
Rails request & middlewares
Santosh 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, 2012
Andy 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 bowels
Creditas
 
A story about gemified engines
A story about gemified enginesA story about gemified engines
A story about gemified engines
mglrnm
 
Ad

Recently uploaded (20)

UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
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