0
votes

I'm using Grails 2.4.2 with the RestfulController and this particular controller uses PagingRestfulController.

I'm trying to run the action searchProducts in the Product Controller when I do a GET on "/product/search" but instead it's running queryForResource.

Grails created listAllResources and queryForResource with the "/product"(resources:'product') URL mapping. Below is my URL Mapping and the applicable parts of the Product Controller. How can I call the search action?

URL Mapping

"/product"(resources:'product')
"/product/search"(controller: 'product'){
    action = [GET: 'searchProducts']
}

Product Controller

protected List<Product> searchProducts(Map params) {
    log.debug("searching products...");
}

protected List<Product> listAllResources(Map params) {
    log.debug("listing all resources...");
}

protected List<Product> queryForResource(Serializable id) {
    log.debug("querying for resources...");
}
1

1 Answers

0
votes

You will need to define a public search action in your controller, which might look something like this:

def search() {
    searchProducts(params)
}

The protected listAllResources and queryForResource methods override helper methods defined in RestfulController, but do not themselves serve as exposed controller actions.

Then, use this nested mapping:

"/product"(resources:'product') {
    "/search"(controller: 'product', action: 'search', method: 'GET')
}