2. Rails Engines
• Engines are stand-alone Rails application that can
be mounted inside of another application
• Controllers and Models are defined within
modules of the engine’s namespace
• architecting an app with engines forces you to
really think through your dependencies and
makes you isolate things from the get go
8. $ rails plugin new awesome --mountable
namespace-isolated engine.
Same as full
• Asset manifest files (application.js and
application.css)
• A namespaced ApplicationController stub
• A namespaced ApplicationHelper stub
• A layout view template for the engine
awesome
|-- Gemfile
|-- Gemfile.lock
|-- MIT-LICENSE
|-- README.rdoc
|-- Rakefile
|-- app
| |-- assets
| |-- controllers
| |-- helpers
| |-- mailers
| |-- models
| `-- views
|-- awesome.gemspec
|-- bin
| `-- rails
|-- config
| `-- routes.rb
|-- lib
| |-- awesome
| | |-- engine.rb
| | `-- version.rb
| |-- awesome.rb
| `-- tasks
| `-- awesome_tasks.rake
`-- test
|-- awesome_test.rb
|-- dummy
9. lib/awesome/engine.rb
module Awesome
class Engine < ::Rails::Engine
isolate_namespace Awesome
end
end
test/dummy/config/routes.rb
Rails.application.routes.draw do
mount Awesome::Engine => "/awesome"
end