I'm using Rails 4 and ActiveAdmin with SQLite.
app
models
system
- admin_user.rb
- customer.rb
resources
- document.rb
config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**/}')]
class System::AdminUser < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable
end
--
So, when I try to run rake db:migrate
I get this error:
LoadError: Unable to autoload constant AdminUser, expected /Users/john/testing/app/models/System/admin_user.rb to define it
Am I doing something wrong?
Rails is automagically able to find correctly-namespaced classes in subfolders of app/models without your having to do anything special. Since you've added subfolders of app/models to the autoload path, Rails now expects to find non-namespaced classes in those locations.
If you delete the autoload path change and define your class as Mohanraj suggested:
# app/models/system/admin_user.rb
module System
class AdminUser
# your code here
# ...
end
end
then you shouldn't have any problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With