raffian
raffian

Reputation: 32056

Grails using inconsistent redirect uri when for the same controller

I've got a simple controller in my Grails app with simple mappings...

TCacheController {
  def index ={}
  def list= {}

}

"/tcache/" (controller: "TCache"){
   action = [GET: "index"]
}

"/tcache/items" (controller: "TCache"){
   action = [GET: "list"]
}

All of my URL's are of the form http://.../tcache/*, and everything works fine. The problem arises when I use <g:actionSubmit> in a view like this...

<g:form controller="TCache">

   <g:actionSubmit class="delete" action="list" value="List Items">

The submit works, but in my list action I have a redirect in case something goes wrong, and that redirect is resulting in 404 because Grails is sending to /TCache/.., not /tcache/...

Under what circumstances is Grails changing upper/lower case of the URI, and is there a way to force it to always use /tcache? I tried using controller="tcache" in the form, but then the action stops working, probably because Grails can't find the controller.

Upvotes: 0

Views: 863

Answers (1)

raffian
raffian

Reputation: 32056

I managed to figure this out on my own. Grails' convention over configuration is great, but sometimes Grails does not always guess correctly.

In the controller, when rendering a view, using literal paths ensures that Grails will not have to guess anything...

TCacheController {
  def index ={}
  def list= {
     render( view: "/tcache/listitems", model:[])
}

instead of...

render( view: "listitems", model:[])

In my case, having multiple controllers, it appears Grails got a bit confused and attempted to prefix /TCache/.. for the full render view path when it should have used /tcache/listitems.

Upvotes: 1

Related Questions