Cake views are just presentation-flavored fragments that fit inside
an application’s layout. For most applications they’re HTML mixed
with PHP, but they may end up as XML, CSV, or even binary data.
Layouts are presentation code that is wrapped around a view, and
can be defined and switched between
if the HTTP method of the
request was POST, try to save the data using the Post model.
When a
request is made to a remote resource, a REST JSON request is generated,
transmitted, and the result received and serialized into a usable Ruby
object.
Relationships between resources can be declared using the standard
association syntax that should be familiar to anyone who uses activerecord
you can define supported formats at the class level and tell in the instance the resource to be represented by those formats.
when a request comes, for example with format xml, it will first search for a template at users/index.xml. If the template is not available, it tries to render the resource given (in this case, @users) by calling :to_xml on it
how to render our resources depending on the format AND HTTP verb
By default, ActionController::Responder holds all formats behavior in a method called to_format.
Suddenly we realized that respond_with is useful just for GET requests
it renders the resource based on the HTTP verb and whether it has errors or not
Your controller code just have to send the resource using respond_with(@resource) and respond_with will call ActionController::Responder which will know what to do.