Reputation: 1
I installed activeadmin in a rails engine that I mounted in my main application. When I try to access the home page I get the following error: uninitialized constant BackOffice::Admin
The code in lib/back_office/engine.rb
require 'devise'
require 'activeadmin'
module BackOffice
class Engine < ::Rails::Engine
isolate_namespace BackOffice
initializer :back_office do
ActiveAdmin.application.load_paths += Dir[File.dirname(__FILE__) + '/back_office/admin']
end
end
end
routes.rb
BackOffice::Engine.routes.draw do
devise_for :admin_users, class_name: "BackOffice::AdminUser"
ActiveAdmin.routes(self)
end
In the routes.rb file of my main app I have this :
mount BackOffice::Engine, at: "/back_office"
Can someone help please?
Upvotes: 0
Views: 108
Reputation: 1
I managed to solve the error then got another one and so on. I solved all issues by creating my engine with the full option and not the mountable one.
Upvotes: 0
Reputation: 2333
An uninitialized constant error would imply that it can't find BackOffice::Admin, so first -- is that constant defined in your engine? Or are you defining Admin under the back_office
namespace without nesting it inside a BackOffice module parent? If you start a rails console and type BackOffice::Admin
, is it able to resolve the class constant?
Does something like this work?
initializer :back_office do
ActiveAdmin.application.load_paths << root.join('back_office/admin')
end
Try putting a binding in the initializer and validate that root.join('back_office/admin')
is constructing the path you're expecting. You might also have to add a before
or after
argument to ensure that your action is running at the right time in ActiveAdmin's initialization flow.
If you run bundle exec rails routes
, are the admin routes you're mounting namespaced correctly? Which route are you going to when you "try to access the homepage"? What feedback is is your app giving you in your development server logs?
Upvotes: 0