[英]Rails 3.2 Gemified Engines: Reaching modules inside a mounted gemified engine
I'm working on an infrastructure for Rails application and I'm trying to take something out of someones existing project. 我正在开发Rails应用程序的基础结构,并且试图从某人的现有项目中获取一些东西。 I am sort of new to rails but I read the guides on plugins and engines ect..
我是Rails的新手,但我阅读了有关插件和引擎的指南等。
So I have a gemified Engine, containing some module. 所以我有一个宝石引擎,其中包含一些模块。 I have a model say SharedPost trying to extend said module and I'm getting the uninitialized constant error
我有一个模型说SharedPost试图扩展所说的模块,我得到了未初始化的常量错误
uninitialized constant Stake::SharedPost
Here's some of what my engine looks like: 这是我的引擎的外观:
#file: lib/stake/shared_post.rb
module Stake
module SharedPost
...
end
end
#file: lib/stake/engine.rb
module Stake
class Engine < ::Rails::Engine
isolate_namespace Stake
end
end
And in the main app I've got 在主应用程序中
#file: Gemfile
...
gem 'stake'
...
#file: config/routes.rb
Pop::Application.routes.draw do
root :to => 'home#index'
mount Stake::Engine, :at => '/stake'
end
#file: app/models/posted.rb
class Posted < ActiveRecord::Base
extend Stake::SharedPost
...
end
end
The main application will load, though with no available data on it. 主应用程序将加载,尽管上面没有可用数据。 While I try to run
当我尝试跑步时
rake db:seed
for example when trying to load the Posted model I get the error uninitialized constant Stake::SharedPost
例如,当尝试加载发布的模型时,出现错误
uninitialized constant Stake::SharedPost
What am I missing to get access to my gem's namespaced modules? 我缺少访问我的gem命名空间模块的信息?
EDIT: I've read into the acts_as pattern and that doesn't seem to be the cleanest way of doing things, plus I'm not sure how to implement that onto my engine. 编辑:我已经读到act_as模式,这似乎不是做事的最干净的方式,再加上我不确定如何在我的引擎上实现它。 Is there another solution?
还有其他解决方案吗?
In lib/stake.rb
are you including the lib/stake/shared_post.rb
file? 在
lib/stake.rb
中,您是否包含lib/stake/shared_post.rb
文件?
It should look something like this: 它看起来应该像这样:
# file lib/stake.rb
require "stake/shared_post.rb"
module stake
....
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.