I have namespace models like so
# /app/models/metadata.rb
module Metadata
class << self
def table_name_prefix
"metadata_"
end
end
end
# /app/models/metadata/object.rb
class Metadata::Object < ActiveRecord::Base
end
# no nested
class TestController < ActionController::API
end
When I run in rails c
it can resolve the Metadata::Object
like so
Metadata::Object.find_by(key: 'XXXX')
Metadata::Object Load (0.3ms) SELECT `metadata_objects`.* FROM `metadata_objects` WHERE `metadata_objects`.`key` = 'XXXX' LIMIT 1
but in controllers, it can't resolve the model ::Metadata::Object.find_by(key: 'XXXX')
NameError Exception: uninitialized constant Metadata::Object
question from:
https://stackoverflow.com/questions/65868186/rails-6-api-only-namespace-models-can-not-resolve-the-namespace-models-in-co 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…