views:

28

answers:

1

Below is a very simple controller with a "search" action that is fired from g:submitButton in a gsp file. My question is, instead of redirecting to the "index" action and view, how do I return to the view that contained the submit button that called this controller's search action?

class DefaultSearchController {
    def searchableService

    def index = {
    }

    def search = {
        def query = params.query
        if(!query){
            redirect(action:"index", params:params)
        }

        try{
            def searchResults =  searchableService.searchEvery( query )
            redirect(action:"index", searchResults)
        }
        catch( e ){
            params.errors = "${e.toString()}"
            redirect(action: "index", params:params)
        }
    }
}
+1  A: 

If the search action is going to be called from various places, I would pass in a parameter to it telling search controller where to redirect to or which view to render the search results with.

cheers

Lee

leebutts
Thanks, sometimes the most difficult answer is the one staring you in the face.
nathan