Components vs engines

Hi,

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

Thanks,
Peter

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

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

On 11/25/05, Stephen W. [email protected] wrote:

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

sigh

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

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

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

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