Having done some speed reading on REST, there seem to be a few primary features: - it is about identifying resources - a uri identifies a resource type, e.g. "orders" (99.9% of examples use the plural of the resource type), like http://example.com/orders - a uri may optionally identify a specific resource like http://example.com/orders/25 - uri may specify resources such as an html form like http://example.com/findOrderForm - there doesn't seem to be one agreed method for combining identification of resource with the action to be taken, for example
- does ..../orders return a list of all orders or an empty order form to create a new order - does ..../orders/1 return a read-only version of an order or a populated form to be used for updating the resource However, when coded as per the T2 manual examples, web2py/T2 considers the controller as the resource(?) For example, given a controller called orders.py then http://example.com/orders/1 can be used to return a form containing order where id=1 using t2.update(db.order) but throws an error when invoked with http://example.com/orders One can implement a version of the REST approach by adding code to the hypothetical orders.py controller (checking the presence of request/ args and using t2.create or t2.update accordingly) but if T2 is intending to be RESTful shouldn't that be built in? In fact, the manual examples are really CRUD (index() does create, display() and update()). So does T2 follow REST? On Oct 21, 8:37 pm, mdipierro <[EMAIL PROTECTED]> wrote: > because I want T2 to follow REST (update/1). Form submission also POST > (id=1&name=massimo&etc) > > On Oct 21, 1:44 pm, billf <[EMAIL PROTECTED]> wrote: > > > My understanding of the mechanism and yours seem exactly the same. My > > question was WHY you designed the t2 update controller to expect a url > > like > > .../update/1 as opposed to .../update?id=1? > > > On Oct 21, 5:07 pm, mdipierro <[EMAIL PROTECTED]> wrote: > > > > Unless I misunderstand the question and I messed up this is how I > > > think it works. > > > > 1) All t2 controllers that need a record id (update, delete, etc.) > > > expect a url like ..../update/1 where args[-1] is the id of the > > > record. > > > There is no exception to this rule. > > > > 2) When you submit a form (create, update, etc) the variables are > > > passed in the form. In the case of update the variables contain the > > > hidden 'id'. This mechanism is inherited from SQLFORM. This may seem > > > redundant but it is not. In fact in t2 you can change 1) and set your > > > own t2.id so that you can create an update form based on a different > > > criteria. In this case there is no id in the url but you still want to > > > make sure SQLFORM knows what id the visitors thinks he/she is editing. > > > > Massimo > > > > On Oct 21, 9:46 am, billf <[EMAIL PROTECTED]> wrote: > > > > > When using the t2.update() method it seems mandatory that the id is > > > > passed in initially as an argument (i.e. part of the path) but on > > > > return from the update form it is expected as a parameter (i.e. ?id=1) > > > > from a hidden input tag? > > > > > This seems to be the only example where an argument is expected. All > > > > other form fields including stamp columns and formkey are passed as > > > > parameters. I just wondered "why the exception"? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---