Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play route syntax for ignoring a part of slug

What we want is basically this:

/foo/*                 controllers.FooController.foo

However this doesn't work.

We have found the following workaround:

/foo/*ignore           controllers.FooController.foo(ignore)

But this makes the code of the method controllers.FooController.foo slightly ugly. Is there a better way to do this?

like image 777
user2206922 Avatar asked Apr 10 '13 07:04

user2206922


1 Answers

Looking at the code over here, the router isn't able to deal with the "slug" part without specifying an identifier... the parser combinator doesn't declare it as optional, and the map (^^) is clearly using it as is.

It could be a good feature request if it wouldn't induce other problems where a pattern will hide all other routes because it's defined higher in the file (or even worst, included).

And it looks like it has been done on purpose if we look here, we can figure out that dynamic parameter cannot be assigned a default value -- indeed, in this case we'll fall in the case I've just mentioned :-/.

My first advice would be to tell you to use ignore as an Option[String] and the action definition to set it as None (rather than an empty String because it's more expressive). My second would be to incite you to wonder if such case is really relevant, because it's error prone and could hide further problems

like image 74
Andy Petrella Avatar answered Nov 10 '22 00:11

Andy Petrella