Prev | Current Page 330 | Next

Brad Ediger

"Advanced Rails"

In addition, many
proxies, caches, and other intermediaries often only support GET and POST, as the
other methods were not in wide use on the Web for many years.
To work around this problem, Rails uses a small hack. Methods other than GET or
POST are sent as POST (the catch-all method as it is neither required to be safe nor
idempotent). To allow the server to determine the original method, it is stored in a
POST variable called _method. The Prototype JavaScript library works in the same way
when calling an action via Ajax.Request or Ajax.Updater with a method other than
GET or POST.
Content Types
The idea that one resource can have multiple representations in different content
types is one of the core principles of REST. It recognizes that different representations
of one thing, whether formatted as JavaScript, HTML, XML, ICS, or in any
other format, is fundamentally the same resource. Rails has introduced rich support
for rendering different responses based on the content type the client wants, via the
respond_to method.
218 | Chapter 7: REST, Resources, and Web Services
The respond_to method yields a responder (an instance of ActionController::
MimeResponds::Responder, usually called format), which can respond to various content
type methods in order to send different content based on the client??™s expectations
(as defined in the Accept request header).


Pages:
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342