padrino/padrino-framework · critical · Padrino::Admin::AccessControlError

You must define an #{settings.admin_model} Model

Error message

You must define an #{settings.admin_model} Model

What it means

The admin app registers a before-filter chain: login_required → current_account → login_from_session → admin_model_obj, which resolves settings.admin_model (default 'Account') via constantize. If that constant does not exist, the NameError is re-raised as this AccessControlError. Because the filter runs on every request, the entire admin section errors until the model exists.

Source

Thrown at padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb:103

          end
        end

        def login_page
          settings.respond_to?(:login_page) && settings.login_page
        end

        def store_location
          settings.respond_to?(:store_location) && settings.store_location
        end

        def login_from_session
          admin_model_obj&.find_by_id(session[settings.session_id])
        end

        def admin_model_obj
          @_admin_model_obj ||= settings.admin_model.constantize
        rescue NameError
          raise Padrino::Admin::AccessControlError, "You must define an #{settings.admin_model} Model"
        end
      end
    end
  end
end

View on GitHub (pinned to 167044f3d5)

Solutions

  1. Create the model the setting names: `bundle exec padrino g model Account email:string password_digest:string role:string` plus migrate (or your custom name)
  2. Make settings.admin_model in admin/app.rb match the real class string: set :admin_model, 'User'
  3. For namespaced models use the fully qualified name and keep the file where Padrino's model autoload finds it
  4. Verify in `padrino console` that typing the constant resolves before booting the admin app

Example fix

# admin/app.rb before
set :admin_model, 'User'   # no User class exists

# after (option A: fix the setting)
set :admin_model, 'Account'

# after (option B: create the model)
# bundle exec padrino g model User email:string role:string
# bundle exec padrino rake ar:migrate
Defensive patterns

Strategy: validation

Validate before calling

# at boot, fail fast with a clear message instead of per-request errors
model = settings.admin_model.to_s
unless Object.const_defined?(model)
  fail "admin_model #{model} is not defined — create it or fix set :admin_model"
end

Type guard

def admin_model_defined?(name)
  Object.const_defined?(name.to_s)
rescue NameError
  false
end

Try / catch

begin
  admin_model_obj&.find_by_id(session[settings.session_id])
rescue Padrino::Admin::AccessControlError
  halt 503, 'admin model missing — check set :admin_model'
end

Prevention

When it happens

Trigger: Registering Padrino::Admin::AccessControl without an Account model (skipping the admin generator's model/migration steps); set :admin_model, 'User' in the admin app.rb when no User class exists or it was renamed; a namespaced or typo'd model string that constantize cannot resolve.

Common situations: Renaming Account to User after generation without updating set :admin_model; passing -m User to the generator but never creating that model; model files moved outside Padrino's models/ autoload path; typo or wrong namespace in the admin_model string.

Related errors


AI-assisted analysis of padrino/padrino-framework@167044f3d5 (2026-08-23). Data as JSON: /api/errors/8c3df26b46aee700. Report an issue: GitHub.