Gist to describe the process of adding a namespaced isolated Rails Engine
to a typical Rails application and adding methods to one of the Rails Engine's
controller and model.
- Rails applicaiton all by itself.
- Rails application with the Rails Engine (FooBar) mounted.
- Rails applicaiton partially extending a controller/model from the Rails Engine.
MyApp
|--- controllers
| |--- a_controller.rb
| |--- b_controller.rb
| |--- c_controller.rb
|
|-------- models
| |--- a.rb
| |--- b.rb
| |--- c.rb
|
|-------- ... and other rails folders
MyApp
|--- controllers
| |--- a_controller.rb
| |--- b_controller.rb
| |--- c_controller.rb
|
|-------- models
| |--- a.rb
| |--- b.rb
| |--- c.rb
|
|---- config
| |---- application.rb ( require 'foobar' )
| |---- routes.rb ( mount FooBar::Engine. :at => '/foobar' )
|
|-------- Gemfile ... gem 'foo_bar'
|
|-------- ... and other rails folders
FooBar
|--- app
| |--- controllers
| | |--- one_controller.rb ( include FooBar::Concerns::Controllers::OneController )
| | |--- two_controller.rb ( include FooBar::Concerns::Controllers::TwoController )
| |
| |-------- models
| | |--- one.rb ( include FooBar::Concerns::Models::One )
| | |--- two.rb ( include FooBar::Concerns::Models::Two )
| |--- views
| |--- one
| | |--- add.html.erb
| | |--- subtract.html.erb
| | |--- multiply.html.erb
| | |--- divide.html.erb
| |
| |--- two
| |--- add.html.erb
| |--- subtract.html.erb
| |--- multiply.html.erb
| |--- divide.html.erb
|
|---- lib
|--- foo_bar.rb
|--- foo_bar
|--- engine.rb
|--- cocnerns
|--- controllers
| |--- one_controller.rb ( within file, extend ActiveSupport::Concern )
| |--- two_controller.rb ( within file, extend ActiveSupport::Concern )
|
|-------- models
|--- one.rb ( within file, extend ActiveSupport::Concern )
|--- two.rb ( within file, extend ActiveSupport::Concern )
We want to add a rails engine (FooBar) and expand the functionality of the
- FooBar::Concerns::Controllers::OnesController in a_controller.rb
- FooBar::Concerns::Models::One in a.rb
MyApp
|--- controllers
| |--- a_controller.rb ( include FooBar::Concerns::Controllers::OnesController )
| |--- b_controller.rb
| |--- c_controller.rb
|
|-------- models
| |--- a.rb ( include FooBar::Concerns::Models::One )
| |--- b.rb
| |--- c.rb
|
|---- config
| |---- application.rb ( require 'foobar' )
| |---- routes.rb ( mount FooBar::Engine. :at => '/foobar' )
|
|-------- Gemfile ... gem 'foo_bar'
|
|-------- ... and other rails folders
FooBar
|--- app
| |--- controllers
| | |--- one_controller.rb ( include FooBar::Concerns::Controllers::OneController )
| | |--- two_controller.rb ( include FooBar::Concerns::Controllers::TwoController )
| |
| |-------- models
| | |--- one.rb ( include FooBar::Concerns::Models::One )
| | |--- two.rb ( include FooBar::Concerns;:Models::Two )
| |--- views
| |--- one
| | |--- add.html.erb
| | |--- subtract.html.erb
| | |--- multiply.html.erb
| | |--- divide.html.erb
| |
| |--- two
| |--- add.html.erb
| |--- subtract.html.erb
| |--- multiply.html.erb
| |--- divide.html.erb
|
|---- lib
|--- foo_bar.rb
|--- foo_bar
|--- engine.rb
|--- concerns
|--- controllers
| |--- one_controller.rb ( within file, extend ActiveSupport::Concern )
| |--- two_controller.rb ( within file, extend ActiveSupport::Concern )
|
|-------- models
|--- one.rb ( within file, extend ActiveSupport::Concern )
|--- two.rb ( within file, extend ActiveSupport::Concern )
I just followed this instruction, but I got: uninitialized constant Concerns::Models exception