0

为什么我的引擎无法加载?

当我启动服务器控制台时显示消息:

`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'

项目规格:

  • 红宝石 1.9.2p180
  • 导轨 3.2.6
4

1 回答 1

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”中

文档指南是熟悉引擎的好方法。如果您喜欢书籍,我建议您阅读Crafting Rails Applications,这是一本小而密集的书,并广泛讨论了引擎(由最出色的 ruby​​ 专家之一:Jose Valim 撰写)。

于 2012-09-12T18:31:13.690 回答