Search code examples
grailsgroovygspgrails-controller

Grails urlMappings action and controller behavior not using controller logic


I have a grails app where the content of urlMappings.groovy file is:

"/" {
   controller="home" 
   view="home"
}

My home controller looks like

class HomeController {
   List products = [
      ['price': 100, 'desc':'a'],
      ['price': 200, 'desc':'b']
   ]

   def home() {
      [products: products]
   }

When I navigate to localhost:8080/myProject/home/home, I have access to "${products}", but when I navigate to localhost:8080/myProject, "${products}" statement is null.

Why is this and how can I make the localhost:8080/myProject act the same way as localhost:8080/myProject/home/home?


Solution

  • You should do

    "/"(controller: 'home', action: 'home')