I want to use a Revel view for adding and editing an item. There's so much duplication between those use cases, having one view makes sense.
When adding an item, my form will post to /item/add
. When editing an item, the post target will be item/edit
. I'll pass this URL as a view argument.
My question is - given I have controller functions:
Item.Add(postvar1, postvar2, ... etc.)
Item.Edit(postvar1, postvar2, ... etc.)
is there a way to get the URL that routes to these controller methods?
I tried calling routes.Item.Add("", "", ...)
but that gives me /item/add?postvar1=&postvar2...
. I could trim/format this string, but I'm wondering if I'm overlooking an existing Revel capability to get this base URL (i.e. /item/add
)?
In my routes file, no arguments are specified. In the controller functions, I'm using auto-binding from the POST variables to the function parameters. Perhaps I can't have my cake and eat it too - I could always remove the auto-binding and this would all work.