Skip to content

Commit f897548

Browse files
authored
Merge pull request #10473 from grails/GRAILS-10472
Fix link generation with class as the resource
2 parents 5a103ab + 9132200 commit f897548

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ class DefaultLinkGenerator implements LinkGenerator, org.codehaus.groovy.grails.
176176
} else if (DomainClassArtefactHandler.isDomainClass(resourceAttribute.getClass(), true)) {
177177
resource = GrailsNameUtils.getPropertyName(resourceAttribute.getClass())
178178
hasId = true
179+
} else if (resourceAttribute instanceof Class) {
180+
resource = GrailsNameUtils.getPropertyName(resourceAttribute)
179181
} else {
180182
resource = resourceAttribute.toString()
181183
}

grails-web-url-mappings/src/test/groovy/org/codehaus/groovy/grails/web/mapping/RestfulResourceMappingSpec.groovy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,8 @@ class RestfulResourceMappingSpec extends Specification{
924924
expect:"The generated links to be correct"
925925
linkGenerator.link(controller:"book", action:"save", method:"POST") == "http://localhost/book"
926926
linkGenerator.link(controller:"book", action:"show", method:"GET") == "http://localhost/book"
927+
linkGenerator.link(resource:"book", action:"show", method:"GET") == "http://localhost/book"
928+
linkGenerator.link(resource:Book, action:"show", method:"GET") == "http://localhost/book"
927929
linkGenerator.link(controller:"book", action:"edit", method:"GET") == "http://localhost/book/edit"
928930
linkGenerator.link(controller:"book", action:"delete", method:"DELETE") == "http://localhost/book"
929931
linkGenerator.link(controller:"book", action:"update", method:"PUT") == "http://localhost/book"
@@ -1033,6 +1035,7 @@ class RestfulResourceMappingSpec extends Specification{
10331035
expect:"The generated links to be correct"
10341036

10351037
linkGenerator.link(controller:"publisher", params:[bookId:1]) == "http://localhost/books/1/publisher"
1038+
linkGenerator.link(resource: Book, method:"GET") == "http://localhost/books"
10361039
linkGenerator.link(resource:"book/publisher", method:"GET", bookId:1) == "http://localhost/books/1/publisher"
10371040
linkGenerator.link(resource:"book/publisher", bookId:1) == "http://localhost/books/1/publisher"
10381041

@@ -1060,3 +1063,7 @@ class RestfulResourceMappingSpec extends Specification{
10601063
return new DefaultUrlMappingsHolder(allMappings)
10611064
}
10621065
}
1066+
1067+
class Book {
1068+
1069+
}

0 commit comments

Comments
 (0)