Rob, I am once again indebted to you! Although the engine_name
specifically does not seem to help (and in fact throws deprecation
warnings), you set my on the path to figuring this out.
Just in case anyone else out there happens to be playing with Rails3
engines (much recommended), and runs into this issue (hopefully not),
the problem was having my engine.rb file and my engine_name.rb files
both sitting side-by-side in the lib dir. The solution is to create
an engine_name dir within lib and put your engine.rb file in there (I
guess Rails only loads the first engine.rb file it finds in a gem or
plugin's lib dir). So...
# Bad (only loads one engine.rb in host app):
/some_engine
|-- lib
|-- some_engine.rb
|-- engine.rb
# Seems to work:
/some_engine
|-- lib
|-- some_engine.rb
|-- some_engine
|-- engine.rb
I feel like I've read that blog post a million times, but somehow
totally overlooked that nuance of the dir structure. Also, I was
using some sample engine code that had engine.rb and gemname.rb both
sitting right in lib. Lesson learned. My engines are back on the
rails! Thanks again!!!
-Gk
On Apr 13, 11:19 am, Rob Kaufman <[email protected]> wrote:
> Hi Gk,
> You may have already solved this, but in your example code, I don't
> see you declare the engine_name. My understanding is that is
> required, or the engines will default to having the same name and
> could account for your problem with having more than one loaded. I
> would also double check your gemspec format and your Gemfile to make
> sure that you are not in any way cross requiring them.
>
> http://www.themodestrubyist.com/2010/03/05/rails-3-plugins---part-2--...
>
> Best,
> Rob
>
>
>
>
>
>
>
> On Tue, Apr 12, 2011 at 09:56, Gk <[email protected]> wrote:
> > Hi all, I'm hoping someone here can maybe shed some insight into this
> > problem I've run into. I'm trying to break several pieces of reusable
> > application functionality into Rails engines. I have no trouble at all
> > getting one engine to work, but the app doesn't seem to load data from
> > subsequent engines. I'm developing multiple engines simultaneously, so
> > I'm requiring them into my testapp's gemfile with the :path option.
>
> > Here's my (simplified) setup (based on my understanding of the bare
> > minimum to setup an engine with a simple model):
>
> > my_engines/engine1/lib/engine1.rb:
>
> > module Engine1
> > require 'engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
> > end
>
> > my_engines/engine1/lib/engine.rb:
>
> > require 'engine1'
> > require 'rails'
>
> > module Engine1
> > class Engine < Rails::Engine
>
> > end
> > end
>
> > my_engines/engine1/app/models/engine1/model1.rb:
>
> > module Engine1
> > class Model1
> > end
> > end
>
> > My second Engine, engine2 is setup identically and in the same parent
> > directory (just with the name engine2 and the model model2).
>
> > I'm using jeweler to package and generate gemspecs for both engines,
> > and I'm requiring both engines in a test application like so:
>
> > my_engines/testapp/Gemfile:
>
> > gem 'engine1', :path => '../engine1'
> > gem 'engine2', :path => '../engine2'
>
> > The weird thing is that when I fire up rails console for my testapp,
> > Engine1::Model1.new works, but Engine1::Model1.new results in
> > "NameError: uninitialized constant Engine2::Model2". This seems to be
> > true for all models, routes, controllers, etc. that I include into any
> > subsequent engines. I've scoured the internet to no avail. Any
> > thoughts?
>
> > --
> > SD Ruby mailing list
> > [email protected]
> >http://groups.google.com/group/sdruby
--
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby