Saturday, 17 August 2013

Rails: Reference an engine from an engine

Rails: Reference an engine from an engine

I have a higher level app, that includes two engines:
Core (engine)
API (engine)
The API engine depends on the models present in the Core engine. I was
wondering how to reference these.



What I have tried
For example, if the Core engine has the model "User", how do I reference
it via the API engine?
module Api
describe User do
routes { Api::Engine.routes }
before :each do
::Core::User.create!
end
....
With this code, I received:
Failure/Error: ::Core::User.create!
NameError:
uninitialized constant Core
So I thought that I had to include the core engine in the api.gemspec file.
s.add_dependency "core", path: "core/"
however, looks like bundler did not like that.
There was a Gem::Requirement::BadRequirementError while loading
api.gemspec:
Illformed requirement [{:path=>"core/"}] from myAppPath/api/api.gemspec:21:in
I also tried
s.add_dependency "core", path: "../core/"
but that gave me a similar error.
Any idea what should be done to reference the Core models from the API
engine?
Thanks!

No comments:

Post a Comment