문제

In rails there's an easy way to add a collection end point to routes. e.g.

resources :books do
  member do
    get 'publisher'    # /books/id/publisher
  end

  collection do
    get 'total_count'  # /books/total_count
  end
end

Is there a similar way to map the total_count endpoint in Grails? The example here ( http://grails.org/doc/2.3.1/guide/single.html#urlMappings ) only shows a member route.

"/books"(resources: "book") {
    "/publisher"(controller:"publisher")
    "/total_count"(controller: "publisher") // ??? can this work?
}

I am currently using Grails 2.3.4.

도움이 되었습니까?

해결책

It was simpler than I thought though if there's a more canonical way of solving this I'd appreciate the feedback.

Basically I defined the collection endpoint before the resource endpoint.

class UrlMappings {
    static mappings = {
        "/books/total_count" (controller: "Book", action: "totalCount", method: "GET")
        "/books" (resources: "Book")
    }
}

So far it appears to be working.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top