Skip to content

startFormTag() throws RouteNotFound for PUT/PATCH/DELETE member routes #3517

Description

@bpamiri

Summary

startFormTag(route="customer", method="delete") throws Wheels.RouteNotFound: Could not find a 'customer' route that matched the supplied arguments. for any resource member route (GET/PATCH/PUT/DELETE), because startFormTag() resolves the named route with the rewritten HTML verb post instead of the original verb.

Repro

With resources(name="customers") configured, rendering a delete/update form:

startFormTag(route="customer", key="1", method="delete")  // throws RouteNotFound
startFormTag(route="customer", key="1", method="put")     // throws RouteNotFound

Root cause

view/forms.cfc:$startFormTagMethod() rewrites method from put/patch/delete to post (for the rendered <form method>), remembering the original verb only for the _method hidden field. startFormTag() then calls urlFor(argumentCollection=arguments) (and later $routeVariables(argumentCollection=arguments)) with arguments.method = "post".

The new $findRoute() disambiguation in global/routing.cfm throws when a method matches none of a same-named route's candidates. Resource member routes carry get/patch/put/delete — never post — so the lookup throws. The previous $findRoute() masked this by silently falling through to the last same-named route.

Suggested fix

Resolve the route with the ORIGINAL verb, then restore the HTML form verb before rendering:

local.method = $startFormTagMethod(args = arguments);
local.formMethod = arguments.method;         // "post"/"get" (HTML verb)
if (Len(local.method)) {
    arguments.method = local.method;         // put/patch/delete (route verb)
}
// ... urlFor(argumentCollection=arguments) and $routeVariables(...) ...
arguments.method = local.formMethod;          // restore before $tag() renders <form method="...">

Impact

Every PUT/PATCH/DELETE form on a resource member route 500s. Not covered by the current view/formsSpec.cfc/routing specs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions