Jasper
Jasper

Reputation: 2176

Rewriting URL for the default action in controllers

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?

Upvotes: 2

Views: 1354

Answers (2)

amra
amra

Reputation: 16875

Try to specify action parameter in link tag as space.

<g:link controller="projects" action=" ">Projects</g:link>

Upvotes: 3

Colin Harrington
Colin Harrington

Reputation: 4459

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>

Upvotes: 1

Related Questions