2
votes

I have a mountable rails engine with Devise. When I copy my migrations and run rake db:migrate in the dummy app it works just fine.

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".

I have this in my routes file:

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

What am I doing wrong ?

1
does your engines gemspec specify a dependency for Devise?Kyle
Hi Kyle, yes: s.add_development_dependency "devise"jakobk
when you gem list from within the project directory, is Devise listed? Also, if you have a development dependency, the gem is only included when you are in development mode. I would do s.add_dependency instead of s.add_development_dependencyKyle
devise is listed as: devise (2.1.2, 2.0.4) - Good idea.. it should be changed. Any idea what else it could be ? - If I include my gem + call engine in the routes file it should pick up devise, as it does in the dummy app (inside the engine)jakobk
I think the problem is that the gem dependencies are not being loaded. Is it sufficient to write: s.add_dependency "devise" in the gemspec ?jakobk

1 Answers

1
votes

I think you need to explicitly require devise in your engine's engine.rb file.

From the Rails guides:

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.