简体   繁体   English

Rails可安装引擎和设计

[英]Rails mountable engine and devise

I have a mountable rails engine with Devise. 我有一个带Devise的可安装导轨引擎。 When I copy my migrations and run rake db:migrate in the dummy app it works just fine. 当我复制迁移并在虚拟应用程序中运行rake db:migrate时,它工作正常。

But when I use a new rails app, add my engine to the gem file, copy migrations and run rake db:migrate I get this error "uninitialized constant Devise". 但是,当我使用一个新的Rails应用程序时,将我的引擎添加到gem文件中,复制迁移并运行rake db:migrate,我得到此错误"uninitialized constant Devise".

I have this in my routes file: 我的路线文件中有这个:

mount Cms::Engine, :at => '/', :as => 'cms'

What am I doing wrong ? 我究竟做错了什么 ?

I think you need to explicitly require devise in your engine's engine.rb file. 我认为您需要明确要求在引擎的engine.rb文件中进行设计。

From the Rails guides : Rails指南

Note that if you want to immediately require dependencies when the engine is required, you should require them before the engine's initialization. 请注意,如果要在需要引擎时立即要求依赖项,则应在引擎初始化之前要求它们。 For example: 例如:

So just add require 'devise' to the top or your engine.rb . 因此,只需将engine.rb require 'devise'添加到顶部或您的engine.rb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM