cold route

37 views
Skip to first unread message

George

unread,
May 22, 2013, 2:48:09 PM5/22/13
to cfwh...@googlegroups.com
Do I have this setup correctly?

<cfscript>
drawRoutes()
.controller("employees")
.get("list")
.post("update")
.delete("delete")
.end()
.root(controller="main", action="index")
.end();
</cfscript>

I want to setup a POST to controller EMPLOYEES to go to action UPDATE, it keeps going to INDEX

Here is my HTTP header for the request
  1. Request Method:
    POST
  2. Status Code:
    200 OK

The response is something I made giving back controller = Employees , action = Index

Donald Humphreys

unread,
May 23, 2013, 8:43:36 AM5/23/13
to cfwh...@googlegroups.com
George,

I think you really want to use RESTful resources for this kind of
thing. If you do this:

<cfscript>
drawRoutes()
.resources(name="employees", only="index,update,delete")
.root(controller="main", action="index")
.end();
</cfscript>

Then you will get the following routes:

GET /employees => employees#index
PUT /employees/[key] => employees#update
DELETE /employees/[key] => employees#delete

The HTTP methods and action names involved are a little different than
what you desired, but this is the standard way in ColdRoute to set up
a controller to edit/delete an entity. If you desire all seven of the
RESTful routes (index, new, create, show, edit, update, delete) to be
created for a resource, you can either add additional entries to the
"only" list, or omit that argument entirely.

Hope this helps.

Don
> --
> You received this message because you are subscribed to the Google Groups
> "ColdFusion on Wheels" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cfwheels+u...@googlegroups.com.
> To post to this group, send email to cfwh...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cfwheels?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Randall Meeker

unread,
May 23, 2013, 11:24:51 AM5/23/13
to cfwh...@googlegroups.com

No, I need to be able to define my routes explicitly. I already use that method on another site. But i need to customize this one.

Donald Humphreys

unread,
May 23, 2013, 11:31:45 AM5/23/13
to cfwh...@googlegroups.com
Alrighty, then here is the code you need:

<cfscript>
drawRoutes()
.controller("employees")
.get(name="list", pattern="")
.post(name="update", pattern="")
.delete(name="delete", pattern="")
.end()
.root(controller="main", action="index")
.end();
</cfscript>

This looks like the closest thing to what you were asking for. Notice
that there are no [key] parameters defined. If you need to pass in a
key to identify records for update or delete, just use pattern="[key]"
instead of empty string.

Also, remember that any request that does not match a route will
result in Wheels looking for the default /[controller]/[action]/[key]
pattern. If you want to confirm the routes generated by ColdRoute,
just go to the plugin page (link for ColdRoute at the bottom of your
site when running in design mode).

George

unread,
May 23, 2013, 12:27:53 PM5/23/13
to cfwh...@googlegroups.com
ah, thanks!
Reply all
Reply to author
Forward
0 new messages