问题描述
当我将其转换为宝石,并将其加载到另一个应用程序中时,我会得到许多未定义的错误,来自我的引擎宝石的依赖。
这是gemspec:
s.add_dependency('paperclip')
s.add_dependency('jquery-rails')
s.add_dependency('rails3-jquery-autocomplete')
s .add_dependency('remotipart')
s.add_dependency('cancan')
在应用程序,当我做捆绑安装时,它列出所有这些依赖项,但是当我运行应用程序时,我收到很多未定义的方法错误(例如从paperclip的has_attachment)。似乎应用程序不加载引擎依赖。
这是默认行为吗?我可以改变吗?
引擎内的插件发生了一样的事情。
如果我手动插入这些宝石,在应用程序Gemfile中,所有的工作...
将它们包含在您的gemfile中并运行bundle install。然后在您的 lib /< your_engine> /engine.rb文件
中要求它们。不要忘记要求rubygems
require'rubygems'
require'paperclip'
require'jquery -rails'
require'rails3-jquery-autocomplete'
require'remotipart'
require'cancan'
然后在你的主机应用程序(包括你的宝石的应用程序)中,运行bundle install / bundle update(bundle update为我做的这个伎俩),然后一切都应该是完美的。您还可以通过在主机应用程序中启动控制台来测试,只需键入模块名称即可。
加载开发环境(Rails 3.0.3)
irb(main):001:0> Paperclip
=> Paperclip
希望这有帮助
I'm doing an engine here, it works alright in stand alone.
When I transform it into a gem, and load it inside another application, I get a lot of undefined errors, coming from my engine gem's dependecies.
Here is the gemspec:
s.add_dependency('paperclip')
s.add_dependency('jquery-rails')
s.add_dependency('rails3-jquery-autocomplete')
s.add_dependency('remotipart')
s.add_dependency('cancan')
In the application, when I do a bundle install, it lists all these dependencies, but as i run the application I receive a lot of undefined methods errors (has_attachment from paperclip for example). It seems that the application doesn't load the engines dependencies.Is this the default behavior? Can I change it?Same thing happened with a plugin inside the engine.
If I insert by hand those gems, in the application Gemfile, all works...
Include them in your gemfile and run bundle install. Then require them in your lib/<your_engine>/engine.rb file
. Don't forget to require rubygems
require 'rubygems'
require 'paperclip'
require 'jquery-rails'
require 'rails3-jquery-autocomplete'
require 'remotipart'
require 'cancan'
Then in your host app (The app where you included your gem) run bundle install/ bundle update (bundle update did the trick for me) and then everything should work perfectly. You can also test this by starting the console in your host app and just type the module name e.g.
Loading development environment (Rails 3.0.3)
irb(main):001:0> Paperclip
=> Paperclip
Hope this helps
这篇关于Rails引擎 - 宝石依赖,如何将它们加载到应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!