# Components vs engines

**URL:** <https://www.ruby-forum.com/t/components-vs-engines/48804>\
**Category:** Rails\
**Created:** [November 25, 2005, 2:55am UTC](https://www.ruby-forum.com/t/components-vs-engines/48804 "2005-11-25T02:55:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![petermichaux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@petermichaux](https://www.ruby-forum.com/u/petermichaux)\
**Post date:** [November 25, 2005, 2:55am UTC](https://www.ruby-forum.com/t/components-vs-engines/48804/1 "2005-11-25T02:55:40Z")

</div>

Hi,

What are the main differences between components vs. engines? It looks  
like  
the are both vertical slices of an application.

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![petermichaux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@petermichaux](https://www.ruby-forum.com/u/petermichaux)\
**Post date:** [November 25, 2005, 9:30am UTC](https://www.ruby-forum.com/t/components-vs-engines/48804/2 "2005-11-25T09:30:16Z")

</div>

[http://rails-engines.rubyforge.org/wiki/wiki.pl?ComponentsPluginsEngines](http://rails-engines.rubyforge.org/wiki/wiki.pl?ComponentsPluginsEngines)

Components are essentially like partials with their own controller  
logic - meant to be rendered within other views. Engines can have  
full-blown views, controllers, helpers, possibly models, libraries…  
all or only as much of that list as you need.

- james

---

<div class="post-metadata">

**Author:** ![petermichaux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@petermichaux](https://www.ruby-forum.com/u/petermichaux)\
**Post date:** [November 25, 2005, 4:30pm UTC](https://www.ruby-forum.com/t/components-vs-engines/48804/3 "2005-11-25T16:30:51Z")

</div>

Peter M. wrote:

> What are the main differences between components vs. engines? It looks  
> like the are both vertical slices of an application.

Components are less feature blessed, but fit very nicely into the  
framework. The Engine is opposite of that.

–Steve

---

<div class="post-metadata">

**Author:** ![petermichaux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@petermichaux](https://www.ruby-forum.com/u/petermichaux)\
**Post date:** [November 25, 2005, 5:23pm UTC](https://www.ruby-forum.com/t/components-vs-engines/48804/4 "2005-11-25T17:23:38Z")

</div>

On 11/25/05, Stephen W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Components are less feature blessed, but fit very nicely into the  
> framework. The Engine is opposite of that.

_sigh_

---

<div class="post-metadata">

**Author:** ![petermichaux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@petermichaux](https://www.ruby-forum.com/u/petermichaux)\
**Post date:** [November 26, 2005, 5:13am UTC](https://www.ruby-forum.com/t/components-vs-engines/48804/5 "2005-11-26T05:13:24Z")

</div>

Hi,

Reading in the Rails book[1] and looking at the ActiveRBAC component[2]  
it  
seems that components have a nasty directory structure. I don’t see any  
hierarchical logic to the following structure. Lumping models and  
controllers and then somehow views are contained in this lump.

components/  
component/  
role.rb  
role\_controller.rb  
role/  
view.rhtml

Integrated in a Rails apps these files would be so nicely divided up in  
the  
app directory

app/  
models/  
role.rb  
controllers/  
role\_controller.rb  
view/  
view.rhtml

Does the seemingly messy directory structure of the component indicate  
that  
the components facility is asked to do too much in this case? Could the  
component’s files structure be improved or does convention make that  
difficult? Would an engine be a better way to go?

Thanks,  
Peter

[1] Agile Web D. with Rails (p376)  
[2] [https://rbaconrails.turingstudio.com/trac/wiki](https://rbaconrails.turingstudio.com/trac/wiki)

---

<div class="post-metadata">

**Author:** ![petermichaux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@petermichaux](https://www.ruby-forum.com/u/petermichaux)\
**Post date:** [November 30, 2005, 2:16am UTC](https://www.ruby-forum.com/t/components-vs-engines/48804/6 "2005-11-30T02:16:13Z")

</div>

Back in the days of 0.9, we were looking at cleaning up components to  
match the app structure. So you’d be able to do things like:

components/  
component/  
controllers/  
role\_controller.rb  
models/  
role.rb  
views/  
role/  
view.rhtml

If I recall, the changes included a few extra default path patterns, a  
2-line change in rendering so that one could override component layouts  
from within the regular app/ tree, and a minor fix to  
uses\_component\_template\_root.

The sticking point was that each component controller would need to  
include the line ‘uses\_component\_template\_root’ which was the one  
sticking point I never figured out how to do. If that could be figured  
out, one could use svn externals to another project’s app/ directory,  
and have a local copy with no fuss.

Alas, I never had the time to finish things, and in the rapid  
development going forward I gave up on them.

> From what I understand though, the reason components is so crappy is  
> because someone half-thought through the idea, and abandoned it.  
> Nobody’s backed it out of the framework, and nobody’s stepped up to do  
> it right either.

- Jamie

---

<div class="post-metadata">

**Author:** ![petermichaux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@petermichaux](https://www.ruby-forum.com/u/petermichaux)\
**Post date:** [November 26, 2005, 9:27am UTC](https://www.ruby-forum.com/t/components-vs-engines/48804/7 "2005-11-26T09:27:17Z")

</div>

> Reading in the Rails book[1] and looking at the ActiveRBAC  
> component[2] it seems that components have a nasty directory  
> structure. I don’t see any hierarchical logic to the following  
> structure.

I think you’ve nailed it - I’ve been avoiding components for the same  
reason. The parts of my app that I’d like to reuse in other projects,  
I’m planning on building as engines.

Hammed

---

<div class="post-metadata">

**Author:** ![petermichaux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@petermichaux](https://www.ruby-forum.com/u/petermichaux)\
**Post date:** [November 30, 2005, 3:28am UTC](https://www.ruby-forum.com/t/components-vs-engines/48804/8 "2005-11-30T03:28:45Z")

</div>

Interesting points there Jamie. I’ve had a bit of a stab at something  
similar, but just like you, I haven’t persisted with it due to the need  
to actually press on with development. I’d really like components to get  
to a point where (or be replaced by) they are identical from rails apps  
themselves. This self-similar structure would allow for better re-use of  
regularly repeated parts of the application which could be tested, and  
possibly also used, as stand alone apps. And before anyone says it, yes  
engines are great, but no they don’t do the same thing. Engines give a  
site an area of functionality (a vertical slice if you will). Components  
give your site a drag and drop ‘think’ which contains complex  
functionality but can be ‘instanced’ many times on the site.

eg:

Engine: I want my site to have blogging functionality, accessed via the  
blog controller.  
Component: I want to be able to add editable blogs to pages on my site,  
accessed via whatever controller manages those pages.

regards,

Craig
