{"record":{"id":"8c3df26b46aee700","repo":"padrino/padrino-framework","slug":"you-must-define-an-settings-admin-model-model","errorCode":null,"errorMessage":"You must define an #{settings.admin_model} Model","messagePattern":"You must define an #(.+?) Model","errorType":"exception","errorClass":"Padrino::Admin::AccessControlError","httpStatus":null,"severity":"critical","filePath":"padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb","lineNumber":103,"sourceCode":"          end\n        end\n\n        def login_page\n          settings.respond_to?(:login_page) && settings.login_page\n        end\n\n        def store_location\n          settings.respond_to?(:store_location) && settings.store_location\n        end\n\n        def login_from_session\n          admin_model_obj&.find_by_id(session[settings.session_id])\n        end\n\n        def admin_model_obj\n          @_admin_model_obj ||= settings.admin_model.constantize\n        rescue NameError\n          raise Padrino::Admin::AccessControlError, \"You must define an #{settings.admin_model} Model\"\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":85,"sourceCodeEnd":109,"githubUrl":"https://github.com/padrino/padrino-framework/blob/167044f3d56b2bce12f943eb826fdb0b0ea94375/padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb#L85-L109","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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)","Make settings.admin_model in admin/app.rb match the real class string: set :admin_model, 'User'","For namespaced models use the fully qualified name and keep the file where Padrino's model autoload finds it","Verify in `padrino console` that typing the constant resolves before booting the admin app"],"exampleFix":"# admin/app.rb before\nset :admin_model, 'User'   # no User class exists\n\n# after (option A: fix the setting)\nset :admin_model, 'Account'\n\n# after (option B: create the model)\n# bundle exec padrino g model User email:string role:string\n# bundle exec padrino rake ar:migrate","handlingStrategy":"validation","validationCode":"# at boot, fail fast with a clear message instead of per-request errors\nmodel = settings.admin_model.to_s\nunless Object.const_defined?(model)\n  fail \"admin_model #{model} is not defined — create it or fix set :admin_model\"\nend","typeGuard":"def admin_model_defined?(name)\n  Object.const_defined?(name.to_s)\nrescue NameError\n  false\nend","tryCatchPattern":"begin\n  admin_model_obj&.find_by_id(session[settings.session_id])\nrescue Padrino::Admin::AccessControlError\n  halt 503, 'admin model missing — check set :admin_model'\nend","preventionTips":["Keep settings.admin_model and the actual model class in sync after any rename","Add a boot-time const_defined?(settings.admin_model) assertion so misconfig fails at startup","Run the admin generator's model and migration steps completely before the first request","Verify the constant resolves in `padrino console` when using namespaced custom models"],"tags":["padrino-admin","authentication","ruby","constantize","model","runtime"],"backgroundTag":"class-not-found","analyzedSha":"167044f3d56b2bce12f943eb826fdb0b0ea94375","analyzedAt":"2026-08-23T12:41:41.049Z","schemaVersion":2},"datasetVersion":"2026-08-23T16:17:53.355Z"}