revel / revel

A high productivity, full-stack web framework for the Go language.
http://revel.github.io
MIT License
13.12k stars 1.39k forks source link

It seems impossible to have an optional parameter in route #1535

Closed syrm closed 2 years ago

syrm commented 3 years ago

Hello,

I have this setup :

GET     /post/:id                               Post.Edit
GET     /post                                   Post.Edit

With my controller like that :

func (c Post) Edit() revel.Result {
    id := c.Params.Get("id")

And in my template :

{{url "Post.Edit"}}
{{url "Post.Edit" .Id}}

And i get this error :

ERROR 18:38:24  revel revel_logger.go:39: render: Template Execution Error (in Page/Index.html): 9: executing "Page/Index.html" at <url "Post.Edit" .Id>: error calling url: reversing Post.Edit: route defines 0 args, but received 1  section=results
notzippy commented 2 years ago

REVEL wants to make things easier, so it pulls out your parameter from the request for you. Your function signature should be

func (c Post) Edit(id string) revel.Result {
   ...