Podobne
- Strona startowa
- McGraw.Hill,.Digital.Animation.Bible.Creating.Professional.Animation.with.3ds.Max.Lightwave.and.Maya.(2004).LiB
- Dołęga Mostowicz Tadeusz Znachor. Profesor Wilczur
- Professional Feature Writing Bruce Garrison(2)
- Professional Feature Writing Bruce Garrison(6)
- Professional Feature Writing Bruce Garrison(3)
- Configuring And Troubleshooting Windows XP Professional
- Professional Feature Writing Bruce Garrison(5)
- Terry Pratchett 05 Czarodzici
- Jordan Robert Korona Mieczy
- McDevitt Jack Brzegi zapomnianego morza
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- thelemisticum.opx.pl
Cytat
Do celu tam się wysiada. Lec Stanisław Jerzy (pierw. de Tusch-Letz, 1909-1966)
A bogowie grają w kości i nie pytają wcale czy chcesz przyłączyć się do gry (. . . ) Bogowie kpią sobie z twojego poukładanego życia (. . . ) nie przejmują się zbytnio ani naszymi planami na przyszłość ani oczekiwaniami. Gdzieś we wszechświecie rzucają kości i przypadkiem wypada twoja kolej. I odtąd zwyciężyć lub przegrać - to tylko kwestia szczęścia. Borys Pasternak
Idąc po kurzych jajach nie podskakuj. Przysłowie szkockie
I Herkules nie poradzi przeciwko wielu.
Dialog półinteligentów równa się monologowi ćwierćinteligenta. Stanisław Jerzy Lec (pierw. de Tusch - Letz, 1909-1966)
[ Pobierz całość w formacie PDF ]
.(The table lists_pathmethods rather than_urlones, but you get both.)Table 3.1: RESTful Routes Table Showing Helpers, Paths, and the Resulting Controller ActionHelper Method GET POST PATCH DELETEclient_path(client) /clients/1 show /clients/1 update /clients/1 destroyclients_path /clients index /clients createedit_client_path(client) /clients/1/edit editnew_client_path /clients/new new(Theeditandnewactions have unique named routes, and their URLs have a special syntax.)Since named routes are now being crossed with HTTP request methods, you ll need to know how to specifythe request method when you generate a URL, so that your GET dclients_urland your POST dclients_urldon t trigger the same controller action.Most of what you have to do in this regard can be summed up in afew rules:1.The default request method is GET.2.In aform_tagorform_forcall, the POST method will be used automatically.3.When you need to (which is going to be mostly with PATCH and DELETE operations), you can specifya request method along with the URL generated by the named route.An example of needing to specify a DELETE operation is a situation when you want to trigger adestroyaction with a link:REST, Resources, and Rails 591 link_to "Delete", auction_path(auction), method: :deleteDepending on the helper method you re using (as in the case ofform_for), you might have to put the methodinside a nested hash:1 form_for "auction", url: auction_path(auction),2 html: { method: :patch } do |f|That last example, which combined the singular named route with the PATCH method, will result in a call totheupdateaction when submitting the form (as per row 2, column 4 of Table 3.1).You don t normally haveto program this functionality specifically, because as we ll see later in the book, Rails automatically figuresout whether you need a POST or PATCH if you pass an object to form helpers.3.5.1 PATCH vs.PUTIf you are coming from a previous version of Rails, you may be wondering why the update action of a RESTfulroute is mapped to the HTTP verb PATCH instead of PUT.In the HTTP standards document RFC 5789², itoutlines that a PUT request to a given resource is meant to completely replace it on the origin server.However,when updating a resource in Rails, rarely, if ever, do you replace an entire resource when performing an update.For example, when updating an Active Record model, Rails sets the attributeupdated_attimestamp, not therequesting client.To follow better HTTP semantics, Rails will be using the HTTP verb PATCH for updates.PATCH allows forboth full and partial updates of a resource, and is more suited to how Rails updates resources.If you are upgrading an existing Rails application, the HTTP verb PUT will still map to the update action inRESTful routes, but it s recommended to use PATCH moving forward.3.5.2 Singular and Plural RESTful RoutesAs you may have noticed, some of the RESTful routes are singular; some are plural.The logic is as follows:1.The routes forshow,new,edit, anddestroyare singular, because they re working on a particularresource.2.The rest of the routes are plural.They deal with collections of related resources.The singular RESTful routes require an argument, because they need to be able to figure out the id of themember of the collection referenced.1 item_url(item) # show, update, or destroy, depending on HTTP verbYou don t have to call theidmethod onitem.Rails will figure it out (by callingto_paramon the object passedto it.)²http://tools.ietf.org/html/rfc5789REST, Resources, and Rails 603.5.3 The Special Pairs: new/create and edit/updateAs Table 3.1 shows,newandeditobey somewhat special RESTful naming conventions.The reason for thishas to do withcreateandupdate, and hownewandeditrelate to them.Typically,createandupdateoperations involve submitting a form.That means that they really involve twoactions two requests each:1.The action that results in the display of the form2.The action that processes the form input when the form is submittedThe way this plays out with RESTful routing is that thecreateaction is closely associated with a preliminarynewaction, andupdateis associated withedit.These two actions,newandedit, are really assistant actions:All they re supposed to do is show the user a form, as part of the process of creating or updating a resource.Fitting these special two-part scenarios into the landscape of resources is a little tricky.A form for editing aresource is not, itself, really a resource.It s more like a pre-resource.A form for creating a new resource issort of a resource, if you assume that being new that is, nonexistent is something that a resource can do,and still be a resource!That line of reasoning might be a little too philosophical to be useful.The bottom line, as implemented inRESTful Rails, is the following: Thenewaction is understood to be giving you a new, single (as opposed toplural) resource.However, since the logical verb for this transaction is GET, and GETting a single resource isalready spoken for by theshowaction,newneeds a named route of its own.That s why you have to use1 link_to "Create a new item", new_item_pathto get a link to theitems/newaction.Theeditaction is understood not to be giving you a full-fledged resource, exactly, but rather a kind of editflavor of theshowresource
[ Pobierz całość w formacie PDF ]