为什么我的引擎无法加载?
当我启动服务器控制台时显示消息:
`load_missing_constant': Expected D:/alexandre/dev/rails/project_name/lib/admin/engine.rb to define Admin::Engine (LoadError)
但是“/lib/admin/engine.rb”存在,其内容为:
Admin::Engine.routes.draw do
get '/' => "admin#index"
get '/error' => "admin#error"
post '/thunder' => "thunder#create", :as => "thunders"
get '/:class' => "admin_models#index"
get '/:class/new' => "admin_models#new"
post '/:class' => "admin_models#create"
get '/:class/:id' => "admin_models#show"
get '/:class/:id/edit' => "admin_models#edit"
put '/:class/:id' => "admin_models#update"
delete '/:class/:id' => "admin_models#destroy"
end
在路线中我添加了这一行:
mount Admin::Engine => '/admin', :as => 'admin'
项目规范:
答案 0 :(得分:0)
文件“/lib/admin/engine.rb”应该定义常量Admin :: Engine,或者更明确地说该文件应该定义类Admin :: Engine。以下是该文件内容的最小示例
module Admin
class Engine < ::Rails::Engine
#isolate_namespace Admin #see http://api.rubyonrails.org/classes/Rails/Engine.html#label-Isolated+Engine
end
end
之前发布的剪辑是关于引擎的路径的,因此应该放在“config / routes.rb”中
documentation和guide是熟悉引擎的好方法。如果你喜欢书籍,我建议你阅读Crafting Rails Applications这是一本很小但非常密集的书,并广泛谈论引擎(由最令人敬畏的红宝石之一:Jose Valim撰写)。