我有一个更高级的应用程序,包括两个引擎:
API引擎依赖于核心引擎中的模型。我在想如何参考这些。
我已经尝试过的
例如,如果Core引擎有"User“模型,我如何通过API引擎引用它?
module Api
describe User do
routes { Api::Engine.routes }
before :each do
::Core::User.create!
end
....有了这个代码,我收到了:
Failure/Error: ::Core::User.create!
NameError:
uninitialized constant Core因此,我认为我必须将核心引擎包括在api.gemspec文件中。
s.add_dependency "core", path: "core/"不过,看起来邦德勒不喜欢那样。
There was a Gem::Requirement::BadRequirementError while loading
api.gemspec:
Illformed requirement [{:path=>"core/"}] from myAppPath/api/api.gemspec:21:in我也试过
s.add_dependency "core", path: "../core/"但这也给了我一个类似的错误。
知道如何从Core引擎引用API模型吗?
谢谢!
Update I试图通过Api的Gemfile将核心引擎添加到Api引擎中。不幸的是,我遇到了一个错误。我开始觉得引擎不应该引用其他引擎。那是真的吗?
/home/.rvm/gems/ruby-2.0.0-p247/gems/railties-
4.0.0/lib/rails/application/routes_reloader.rb:10:in `rescue in execute_if_updated':
Rails::Application::RoutesReloader#execute_if_updated delegated to
updater.execute_if_updated, but updater is nil: #
<Rails::Application::RoutesReloader:0x007fb53b67bce8 @paths=
["/home/myApp/api/spec/dummy/config/routes.rb", "/home/myApp/core/config/routes.rb",
"/home/myApp/api/config/routes.rb"], @route_sets=[#
<ActionDispatch::Routing::RouteSet:0x007fb53b3b8420>, #
<ActionDispatch::Routing::RouteSet:0x007fb53b6008b8>, #
<ActionDispatch::Routing::RouteSet:0x007fb53b6b9b60>]> (RuntimeError)除了下面的答案之外,我还想补充一点:文件没有任何关于gem存储位置的信息,即它不会指向git存储库或文件路径等。本文将对此进行解释:
http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
发布于 2013-08-18 09:33:06
这里有两件事需要理解:
如果您的引擎应该是公共的(比如dependency ),那么您需要在Core中引用您的gemspec依赖项。但是,您将无法使用path引用它。但是对于公共引擎来说,这不是问题,因为公共引擎在某个时候会出现在Rubygems上。
如果您的引擎是私有的,并且只用于清理代码库,那么将gem 'core', path: '../core'添加到引擎的Gemfile是可以的。
这里要记住的是:
gemspec用于声明依赖项(引擎工作所需的gems )Gemfile用于本地或测试依赖项声明。https://stackoverflow.com/questions/18295343
复制相似问题