Ruby on rails 在Rails(4.1.x)引擎中使用库?
因此,这里的核心问题是以下信息:Ruby on rails 在Rails(4.1.x)引擎中使用库?,ruby-on-rails,rails-engines,Ruby On Rails,Rails Engines,因此,这里的核心问题是以下信息: `<class:ApplicationController>': uninitialized constant Xaaron::Core (NameError) 我有一个名为core/的目录,其中有一个名为loder.rb的文件 core的内部是一个名为controllers的目录,另一侧是一个名为user\u controller的文件,看起来像: module Xaaron module Core module UserContro
`<class:ApplicationController>': uninitialized constant Xaaron::Core (NameError)
我有一个名为core/的目录,其中有一个名为loder.rb的文件
core的内部是一个名为controllers的目录,另一侧是一个名为user\u controller的文件,看起来像:
module Xaaron
module Core
module UserController
def assign_to_member_group(user)
memeber = Xaron::Group.find('member')
user.add_group = memeber.group_name
end
end
end
end
要加载此文件,我有一个加载程序文件:
module Xaaron
module Core
module Loader
include Xaaron::Core::Controllers::UserController
end
end
end
我认为这是不必要的,因为在engine.rb文件中我有:config.autoload_path我想你的问题在于config.autoload_path澄清了你想要加载什么以及从哪里加载。我的意思是,Xaaron::Core::Loader是否来自main_应用程序中的engine和ApplicationController?很抱歉:Xaaron::Core::Loader位于Xaaron/lib/Xaaron/Core/Loader.rb中-它是engineNow I get Name的一部分错误:rails控制台中未初始化的常量Core。我添加了config.autoload\u路径,但没有添加。您是否签入了什么路径文件。展开\路径.././xaaron/core,\文件\通过简单的放置或调试来展开?如果是,您的模块是否在该目录中?
module Xaaron
module Core
module Loader
include Xaaron::Core::Controllers::UserController
end
end
end
module Xaaron
class ApplicationController < ActionController::Base
...
include Xaaron::Core::Loader
...
end
end