-
-
Save pledbrook/9e1e6e0e1a520b6a3612 to your computer and use it in GitHub Desktop.
| ratpack { | |
| ... | |
| handlers { | |
| get { | |
| ... | |
| } | |
| prefix("blog") { | |
| handler { | |
| redirect 303, "http://blog.cacoethes.co.uk/${get(PathBinding).pastBinding}" | |
| } | |
| } | |
| assets "public" | |
| } | |
| } |
robfletcher
commented
Jun 26, 2014
There's no method byMethod(Closure) on the ratpack object. I did try
prefix("blog") {
handler {
byMethod {
get {
...
}
}
}
}
That at least doesn't throw an exception. In fact, it works now. I tried it before but it hung for some reason. I can't seem to eliminate the handler() call though.
Can't you just do:
handler("blog") {
byMethod {
get {
…
}
}
}
Is there a reason you need to use prefix? As I understand it that's for nesting handlers for sub-paths.
@robfletcher Apparently handler(path, ...) only triggers if the path matches exactly (so says the [API docs](http://www.ratpack.io/manual/current/api/ratpack/groovy/handling/GroovyChain.html#handler%28java.lang.String, groovy.lang.Closure%29) anyway). As far as I can tell, prefix() is the only one that does a match on just the start of the path.
You have it right...
prefix("blog") {
handler {
byMethod {
get {
...
}
}
}
}This is the right approach.
@pledbrook I see, didn't realize what you were doing with the remainder of the path there
@danveloper The first time I tried that the app was hanging, which is why I resorted to Help By Twitter. Still, it seems unnecessarily verbose and confusing. Not sure why byMethod() isn't a handler itself.