Search code examples
grails

UrlMapping to Index is not working


I am trying to get my Index which in my case is just localhost:8080 to go to a different page. This code is not working and I'm just going to the index page instead of rendering "this worked"

My UrlMappings file looks like this:

package appworld

class UrlMappings {

    static mappings = {

        "/$controller/$action?/$id?(.$format)?"{
            constraints {
                // apply constraints here
            }
        }

        "/" {
            controller = "Home"
            action = "isUserLoggedIn"
        }

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

The method in HomeController.groovy looks like:

def isUserLoggedIn() {
   println("We made it from index")
   render "this worked"
}

Solution

  • It looks like your syntax is off. Try:

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