{"record":{"id":"ee65966efb5fe534","repo":"padrino/padrino-framework","slug":"model-klass-name-could-not-be-found-perhaps","errorCode":null,"errorMessage":"Model '#{klass_name}' could not be found!\nPerhaps you would like to run 'bundle exec padrino g model #{klass_name}' to create it first?","messagePattern":"Model '#(.+?)' could not be found!\nPerhaps you would like to run 'bundle exec padrino g model #(.+?)' to create it first\\?","errorType":"exception","errorClass":"Padrino::Admin::Generators::OrmError","httpStatus":null,"severity":"error","filePath":"padrino-admin/lib/padrino-admin/generators/orm.rb","lineNumber":25,"sourceCode":"      # Defines a generic exception for the admin ORM handler.\n      class OrmError < StandardError; end\n\n      ##\n      # Defines the generic ORM management functions used to manipulate data for admin.\n      class Orm\n        attr_reader :klass_name, :klass, :name_plural, :name_singular, :orm, :name_param\n\n        def initialize(name, orm, columns = nil, column_fields = nil)\n          name            = name.to_s\n          @klass_name     = name.underscore.camelize\n          @klass          = @klass_name.constantize rescue nil\n          @name_param     = name.underscore.gsub('/', '_')\n          @name_singular  = name.underscore.gsub(%r{^.*/}, '') # convert submodules i.e. FooBar::Jank.all # => jank\n          @name_plural    = @name_singular.pluralize\n          @orm            = orm.to_sym\n          @columns        = columns\n          @column_fields  = column_fields\n          raise OrmError, \"Model '#{klass_name}' could not be found!\\nPerhaps you would like to run 'bundle exec padrino g model #{klass_name}' to create it first?\" if @columns.nil? && @klass.nil?\n        end\n\n        def activerecord?\n          case orm\n          when :activerecord, :minirecord then true\n          else false\n          end\n        end\n\n        def field_type(type)\n          type = :string if type.nil?\n          type = type.to_s.demodulize.downcase.to_sym unless type.is_a?(Symbol)\n\n          case type\n          when :integer, :float, :decimal   then :text_field\n          when :string                      then :text_field\n          when :text                        then :text_area\n          when :boolean                     then :check_box","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/padrino/padrino-framework/blob/167044f3d56b2bce12f943eb826fdb0b0ea94375/padrino-admin/lib/padrino-admin/generators/orm.rb#L7-L43","documentation":"Padrino::Admin::Generators::Orm wraps a model for the admin/admin_page generators. At initialize it constantizes the underscored/camelized name (rescuing to nil) and raises OrmError when the class cannot be resolved and no explicit columns were passed — the generator cannot introspect a model that does not exist. The message names the exact model generator command to run first.","triggerScenarios":"`padrino g admin_page Foo` when models/foo.rb does not exist or does not define class Foo; a typo'd model name; a namespaced model whose constant cannot be resolved from the given name; running the generator outside the app root so model files are not found.","commonSituations":"Running admin_page before creating or migrating the model; renaming a generated model class without renaming the file; namespaced models (Orm builds the constant via name.underscore.camelize); model file present but empty or class commented out.","solutions":["Create the model first: `bundle exec padrino g model Foo`, run migrations, then re-run `padrino g admin_page Foo`","Check the spelling and casing of the name passed to admin_page against the actual class name","For namespaced models, pass a name whose underscore.camelize resolves to the real constant and make sure the file is loaded"],"exampleFix":"# before\nbundle exec padrino g admin_page Post   # models/post.rb absent\n\n# after\nbundle exec padrino g model Post title:string body:text\nbundle exec padrino rake ar:migrate\nbundle exec padrino g admin_page Post","handlingStrategy":"validation","validationCode":"name = 'Post'\nif (name.to_s.underscore.camelize.constantize rescue nil).nil?\n  abort \"run `bundle exec padrino g model #{name}` before generating its admin page\"\nend","typeGuard":"def admin_model_loadable?(name)\n  klass = (name.to_s.underscore.camelize.constantize rescue nil)\n  !klass.nil? && klass.respond_to?(:columns)\nend","tryCatchPattern":"begin\n  Padrino::Admin::Generators::Orm.new('Post', orm)\nrescue Padrino::Admin::Generators::OrmError => e\n  puts e.message # suggests the exact `padrino g model` command\nend","preventionTips":["Generate and migrate the model before running admin_page for it","Copy-paste the model name from the file in models/ rather than typing it","For namespaced models, verify the constant resolves in `padrino console` first"],"tags":["padrino-admin","generator","orm","model","scaffolding"],"backgroundTag":"model-class-not-found","analyzedSha":"167044f3d56b2bce12f943eb826fdb0b0ea94375","analyzedAt":"2026-08-23T12:41:41.049Z","schemaVersion":2},"datasetVersion":"2026-08-23T16:17:53.355Z"}