PDA

View Full Version : Url generations and redirect problems.



ShurikAg
Dec 3rd, 2010, 03:06 PM
Hi,

First, I have to say that I'm new for Grails :) So, some "trivial" questions are possible :)

In my app I have a UrlMapping as follows:


class UrlMappings {

static mappings = {

name dashboard: "/" {
controller = "dashboard"
action = "index"
}

name login: "/login"(controller:"auth"){
action = [GET:"login", POST:"loginDo"]

}

"500"(view:'/error')
}
}


When in one of my controllers I'm trying to redirect to the login page like this:

redirect(controller: 'auth', action:'login')
it redirects me to: http://host/auth/login

1. What is the right way to generate the link defined in the mapping?
2. How can I use the name of named mapping to generate the url's (not links)?
I found a way to generate a links:

<g:link mapping="personList">List People</g:link>

Didn't find anything similar for URLs only...

Thanks.

ShurikAg
Dec 6th, 2010, 12:51 AM
Really? Nobody knows?

pledbrook
Dec 6th, 2010, 04:21 AM
If you want to redirect to a RESTful URL, don't include the action:


redirect controller: "auth"


If you want to generate a URL, you can use the 'createLink' tag from a controller as if it were a method:


def index = {
println g.createLink(mapping: "login")
}

Hope that helps.

ShurikAg
Dec 6th, 2010, 04:27 AM
What about in filter?