The Rails         Engine That           Could?Saturday, April 28, 2012
Hi!        www.launchware.com        on the InterTubes                                    Hiring                          ...
What I Can Tell You                            About Rails Engines                           • A Brief History            ...
Out With The Old...    • Components in Rails            Beta and Rails 1    • Components            removed in Rails 2Satu...
...In With the New                                   • Engines in Rails 3                                   • Enginex as p...
Generating                     rails generate plugin thomas --mountableSaturday, April 28, 2012
Saturday, April 28, 2012
Saturday, April 28, 2012
Manage Dependencies                         In Your Gemspec     Shift Your PerspectiveSaturday, April 28, 2012
Shifting Perspectives                      • Think like an API designer                      • Favor composition over inhe...
Maintain Perspective                      • Do as you would normally:                       • Write migrations            ...
GotchasSaturday, April 28, 2012
Routes                      • Routes are loaded where you mount                           them                      • Only...
Namespacing           • Namespace Your Engine - it will save you lots of                    pain.           • If you must ...
Routes                      • Routes are loaded where you mount                           them                      • Only...
Consumer::Application do        Thomas::Routes::UserRoutes.draw(self)        #custom routes here        Thomas::Routes::Sc...
Named Routes Helpers                      • If you don’t namespace, I found these to be                           incredib...
class ApplicationController < ActionController::Base      include Thomas::Engine.routes.url_helpers      include ActionDis...
Saturday, April 28, 2012
Devise                      • Wiring I18n load paths is deferred until the                           app comes up, disallo...
class Thomas::Engine < Rails::Engine            config.after_initialize do              Rails.application.config.after_ini...
Inherited Resources                             And Responders                                Doesn’t Work                ...
Saturday, April 28, 2012
Wrong Thomas...                              ...Go B’sSaturday, April 28, 2012
class ApplicationController < ActionController::Base  def self.engine_inherit_resources      inherit_resources      self.r...
Deploying Private                             Gems To Heroku                      • Bundle with your github credentials in...
Overall, Engines Are                                 Great             • There’s still room for                      impro...
Thanks!                      • I’ll post slides @ www.launchware.com                      • Chat me up on Twitter: @dpicke...
Upcoming SlideShare
Loading in …5
×

Engines Lightning Talk

306 views

Published on

A lightning talk presented to BostonRB in April of 2012

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
306
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Engines Lightning Talk

  1. 1. The Rails Engine That Could?Saturday, April 28, 2012
  2. 2. Hi! www.launchware.com on the InterTubes Hiring dpickett on TwitterSaturday, April 28, 2012
  3. 3. What I Can Tell You About Rails Engines • A Brief History • A Rails Engine In Rails 3.1 • Implementation Gotchas • Deployment Gotchas With Heroku • ConclusionsSaturday, April 28, 2012
  4. 4. Out With The Old... • Components in Rails Beta and Rails 1 • Components removed in Rails 2Saturday, April 28, 2012
  5. 5. ...In With the New • Engines in Rails 3 • Enginex as part of Rails 3.1Saturday, April 28, 2012
  6. 6. Generating rails generate plugin thomas --mountableSaturday, April 28, 2012
  7. 7. Saturday, April 28, 2012
  8. 8. Saturday, April 28, 2012
  9. 9. Manage Dependencies In Your Gemspec Shift Your PerspectiveSaturday, April 28, 2012
  10. 10. Shifting Perspectives • Think like an API designer • Favor composition over inheritance • Obey SOLID principles for more maintainable codeSaturday, April 28, 2012
  11. 11. Maintain Perspective • Do as you would normally: • Write migrations • Seed data • Run rake tasks • Run generatorsSaturday, April 28, 2012
  12. 12. GotchasSaturday, April 28, 2012
  13. 13. Routes • Routes are loaded where you mount them • Only one opportunity for placement • No flexibility to divide up routes for fine tuning prioritiesSaturday, April 28, 2012
  14. 14. Namespacing • Namespace Your Engine - it will save you lots of pain. • If you must in your consuming application, use ActiveSupport’s require_dependency to override: require_dependency Thomas::Engine.root.join(“app/models/user”).to_s class User < ActiveRecord::Base #override the engine here endSaturday, April 28, 2012
  15. 15. Routes • Routes are loaded where you mount them • Only one opportunity for placement • No flexibility to divide up routes for fine tuning prioritiesSaturday, April 28, 2012
  16. 16. Consumer::Application do Thomas::Routes::UserRoutes.draw(self) #custom routes here Thomas::Routes::ScheduleRoutes.draw(self) end module Thomas module Routes module UserRoutes def self.draw(map) map.instance_eval do resources :user... end end end end endSaturday, April 28, 2012
  17. 17. Named Routes Helpers • If you don’t namespace, I found these to be incredibly problematic • You must include helpers in your application controller and in your request specs/testsSaturday, April 28, 2012
  18. 18. class ApplicationController < ActionController::Base include Thomas::Engine.routes.url_helpers include ActionDispatch::Routing::PolymorphicRoutes end You’ll use these two lines a lot. Apply when you get an undefined *_path or *_url methodSaturday, April 28, 2012
  19. 19. Saturday, April 28, 2012
  20. 20. Devise • Wiring I18n load paths is deferred until the app comes up, disallowing override abilitySaturday, April 28, 2012
  21. 21. class Thomas::Engine < Rails::Engine config.after_initialize do Rails.application.config.after_initialize do paths = I18n.load_path.delete_if do |p| p =~ /devise-/ end #put devise’s default locales in its place I18n.load_path = paths + I18n.load_path I18n.reload! end endSaturday, April 28, 2012
  22. 22. Inherited Resources And Responders Doesn’t Work Drops Your ResponderSaturday, April 28, 2012
  23. 23. Saturday, April 28, 2012
  24. 24. Wrong Thomas... ...Go B’sSaturday, April 28, 2012
  25. 25. class ApplicationController < ActionController::Base def self.engine_inherit_resources inherit_resources self.responder = MobileResponder end endendSaturday, April 28, 2012
  26. 26. Deploying Private Gems To Heroku • Bundle with your github credentials in plaintext • Maintain your own gem server • Write a rake task to vendor the gem and commit when deploying • NEW: http://www.gemfury.com/Saturday, April 28, 2012
  27. 27. Overall, Engines Are Great • There’s still room for improvement, but they’re awesome once you get going • They will challenge you as a developer and as a Rails Framework userSaturday, April 28, 2012
  28. 28. Thanks! • I’ll post slides @ www.launchware.com • Chat me up on Twitter: @dpickett • Chat me up on IRC: dpickett in #boston.rb • We’re hiring!Saturday, April 28, 2012

×