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

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 

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