Skip to content

Commit 65e4379

Browse files
committed
resolve nested model classes in HomeHelper#metadata
`metadata(cls)` did a bare `LinkedData::Models.const_get(name)`, so requests like `GET /metadata/Reply` blew up with `NameError: uninitialized constant LinkedData::Models::Reply` — `Reply` lives under `LinkedData::Models::Notes`, not at the top level. `routes_by_class` already has sub-module search for the same reason; `metadata` was missing the mirror. Extract a small `resolve_model_class(name)` helper that tries the top-level lookup first and falls back to scanning `LinkedData::Models.constants` for the name, matching the behavior of `routes_by_class`. This restores `GET /metadata/Reply` and any other nested model class (e.g. `Users::Role`, `Users::NotificationType`). test_metadata_route_resolves_submodule_class now passes.
1 parent 1c3d329 commit 65e4379

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

helpers/home_helper.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,24 @@ def resource_collection_link(cls)
4242

4343
def metadata(cls)
4444
unless cls.is_a?(Class)
45-
cls = cls.singularize
46-
cls = LinkedData::Models.const_get(cls)
45+
cls = resolve_model_class(cls.singularize)
4746
end
4847
metadata_all[cls]
4948
end
5049

50+
# Resolve a model class by bare name, checking LinkedData::Models first
51+
# and falling back to sub-modules (e.g. LinkedData::Models::Notes::Reply
52+
# for "Reply"). Mirrors the sub-module search in `routes_by_class`.
53+
def resolve_model_class(name)
54+
LinkedData::Models.const_get(name)
55+
rescue NameError
56+
LinkedData::Models.constants.each do |const|
57+
sub_cls = LinkedData::Models.const_get(const).const_get(name) rescue nil
58+
return sub_cls if sub_cls.is_a?(Class)
59+
end
60+
raise
61+
end
62+
5163
def sample_objects
5264
ontology = LinkedData::Models::Ontology.read_only(id: LinkedData.settings.rest_url_prefix+"/ontologies/BRO", acronym: "BRO")
5365
submission = LinkedData::Models::OntologySubmission.read_only(id: LinkedData.settings.rest_url_prefix+"/ontologies/BRO/submissions/1", ontology: ontology)

0 commit comments

Comments
 (0)