Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Creating Mountable Engines

Creating Mountable Engines

With Rails 4.0 killing off the humble plugin, there is never a better time to learn how to create reusable code using Engines. Creating an engine can be as simple as adding a model, or a complex as an entire content management system. Using the Asset Pipeline, even javascript and css files can be packaged and shared, making projects cleaner and more maintainable than ever before.

This talk will cover how developers can create their own engines, to add new controllers/models/views, rake tasks and/or generators. It will cover how engines can interact with Rails having their own initializers and middleware. Finally, based on our experiences converting BrowserCMS and its entire module ecosystem to work as mountable engines, this talk will cover how to make engines that are designed to work together, extend each other engine’s behavior and make it easy for developers to upgrade when you release new versions.

peakpg

May 01, 2013
Tweet

More Decks by peakpg

Other Decks in Technology

Transcript

  1. Agenda Agenda • - Why I care • - How to make

    one • - Things you can do • - Working with others
  2. Evolving a CMS with engines Evolution of a CMS 3.0

    Engines Introduced 3.1 -Mountable -Initializers -Asset Pipeline 4.0 2.3 Gems over plugins
  3. What are engines? What are Engines? Responsibilities: •  Business Domain

    •  Selling Stuff •  Managing Users •  Blogging App #2 ?
  4. Route helpers Route Helpers <%= main_app.root_url %> # => /

    <%= rubypress.root_url %> # => /rubypress <%= rubypress.page_path(@page) %> # => /rubypress/pages/1
  5. Out of the gem, into the project From Gem to

    Project $ rake rubypress:install:migrations - Copies from gem’s db/migrate into a project - Won’t overwrite existing
  6. Write a README Write a Readme gem "rubypress" $ bundle

    install $ rake rubypress:install:migrations $ rake db:migrate mount Rubypress::Engine=>"/rubypress"
  7. Challenges on our quest Challenges A. Incompatible dependencies B. Rails

    has no common security model C. Mismatched user interfaces
  8. Managing your engine dependencies Solving Dependencies - Minimize dependencies -

    Be Rational: Major.Minor.Build (i.e. 3.5.4) - Major – Backwards incompatible - Minor – New features - Build – Details - Robustness Principle: - Be liberal in what you accept - ~> 2.0 better than ~>2.0.0