Rails 3.1 Engines: Full vs. Mountable

617 views
Skip to first unread message

astjohn

unread,
Jul 25, 2011, 3:27:04 PM7/25/11
to Ruby on Rails: Talk
Hi all,

I was hoping someone could please clarify the differences between a
full engine and a mountable one.

I have noticed the following:

** Full Engine **
- With a full engine, the parent application inherits the routes from
the engine. It is not necessary to specify anything in parent_app/
config/routes.rb. Specifying the gem in Gemfile is enough. The
engine routes are specified as:

# my_engine/config/routes.rb
Rails.application.routes.draw do
# whatever
end

- No namespacing of models, controllers, etc. These are immediately
accessible to the parent application.


** Mountable Engine **
- The engine's namespace is isolated by default.

# my_engine/lib/my_engine/engine.rb
module MyEngine
class Engine < Rails::Engine
isolate_namespace MyEngine
end
end

- With a mountable engine, the routes are namespaced and the parent
app can bundle this functionality under a single route:

# my_engine/config/routes.rb
MyEngine::Engine.routes.draw do
#whatever
end

# parent_app/config/routes.rb
Rails.application.routes.draw do
mount MyEngine::Engine => "/engine", :as => "namespaced"
end

- Models, controllers, etc are isolated from the parent application -
although helpers can be shared easily.


Is this correct and are these the main differences? Are there any
other differences between a full and mountable engine that I missed?

Thanks,
Adam

astjohn

unread,
Jul 28, 2011, 9:11:19 AM7/28/11
to Ruby on Rails: Talk
I take it no one has poked around with the Rails 3.1 engines yet?


-Adam

Paul

unread,
Jul 28, 2011, 10:14:30 AM7/28/11
to rubyonra...@googlegroups.com
I'm interested in this, too, but I haven't used 3.1 yet. Let us know
what you find out!

astjohn

unread,
Aug 8, 2011, 1:28:22 PM8/8/11
to Ruby on Rails: Talk
Hi Paul,

Here's what I have found so far:

http://www.astjohn.ca/blog/rails-31-engines-mountable-or-full-part-1

I'll post Part 2 later tonight. Hope that helps you out.

Cheers,
Adam
Reply all
Reply to author
Forward
0 new messages