Circular dependency detected while autoloading constant when loading constant

It looks like the primary issue may just be that you haven’t namespaced your UsersController under the Admin namespace, here:

class UsersController < Admin::BaseController

Simple fix:

class Admin::UsersController < Admin::BaseController

However, I suggest that you also break out your namespaces out into distinct parts to save future headache. So instead of the above, do this:

# app/controllers/admin/users_controller.rb
module Admin
  class UsersController < Admin::BaseController
    # ...
  end
end

And do the same with all other namespaced controllers, such as:

# app/controllers/admin/base_controller.rb
module Admin
  class BaseController < ApplicationController
    # ...
  end
end

This way, as Rails is loading and autoloading and so forth it will always be sure to define the Admin module before attempting to load the classes under it. Sometimes you get unknown constant errors otherwise. The reasoning is a bit complex, but if you’d like to have a look check out this post.

UPDATE

On Rails Edge, there is now an official Guide on the topic of Auto Loading of Constants.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)