zeka wrote:
I have spent a couple of days trying to figure out how to put
different pieces of our (quite large) app into components.
The idea was to use Rails 3 Engines/Railties and place them in /lib.
Each would have its own [app/views, app/helpers, app/models and app/
controllers]
We also needed an ability for those components to override views/
helpers/controllers in the parent “container app”.
No luck there. Perhaps this snippet illustrates better what I was
trying to do: http://pastie.org/1180038
Is it what engines/railties are for?
And if not, how can I “componentize” some of the partials we have?
Our app needs certain pieces present/removed depending on which
installation we do. Right now we have a bunch of if/elses that depend
on configuration, and it looks a bit ugly, so I wanted to take some
partials+controllers+models and move them into lib/xxx and then by
including/excluding a single “require lib/xxx” I was planning to
enable/disable them.
This is a pretty big topic, and I haven’t found a good all-in-one
resource either, but after a few days of poking around and re-reading
articles, I’ve just started to componentize core libs I use in my apps
as well.
First, as for the path overrides, no need to inject paths yourself.
Rails will look in certain places if you provide those places. You tried
using /lib, but the correct place is in /vendor/plugins. Rails will look
inside all /vendor/plugins/{WHATEVER}/app/views folders. So you were
close. Don’t bother with the path shift business.
Making a plugin is as simple as using the rails generator, but making
engines requires a slightly different organization of the files. This is
a good place to start, but there’s some out of date info. The /rails
folder inside the plugin that the article suggests making is obsolete.
http://guides.rubyonrails.org/plugins.html#organize-your-files
As for creating proper Rails3 engines, these are the links that I went
round and round with until it started to make sense:
https://gist.github.com/e139fa787aa882c0aa9c
http://www.themodestrubyist.com/2010/03/01/rails-3-plugins---part-1---the-big-picture/
http://www.themodestrubyist.com/2010/03/05/rails-3-plugins---part-2---writing-an-engine/
http://github.com/krschacht/rails_3_engine_demo
After that you start making your engines and plugins into gem, and they
become even easierto use in multiple projects.
Hope that gives you a some help.
– gw