views:

64

answers:

2

I'm having trouble rewriting URL's in Grails:

I've got 2 controllers BlogController and ProjectsController each with a default def index = { } and matching view.

Now when I create the following links:

<g:link controller="blog">Blog</g:link>
<g:link controller="projects">Projects</g:link>

They get translated to http://localhost:8080/myapp/blog/index and http://localhost:8080/myapp/projects/index. But want them (and all other controllers default action) to be without the trailing /index.

Can anyone help me do this?

+1  A: 

Try using a Named URL Mapping

Add this to your grails-app/conf/UrlMappings.groovy

    name blog: "/blog" {
            controller = "blog"
            action = "index"
    }
    name projects: "/projects" {
            controller = "projects"
            action = "index"
    }

and change your links to use the mapping parameter:

<g:link mapping="blog">Blog</g:link>
<g:link mapping="projects">Projects</g:link>
Colin Harrington
This works, but it doesn't really scale well. Every controller would need his own named mapping.
Psy
+1  A: 

Try to specify action parameter in link tag as space.

<g:link controller="projects" action=" ">Projects</g:link>
amra
Works like a charm, thanks.
Psy