RESTful RESOURCE PARTIAL UPDATE (Single Attribute Update)

I am having a hard time understanding updating a partial resource.
This was talked about at railsconf here on page 29. ... _scott.pdf . The problem i
am specifically referring to is having a user resource with attributes
such as name, email, password, created_at, etc. Following rest, when
creating a user, all these attributes are created. But the same goes
with updating a user. All of these attributes must be updated.

But what about the scenario when i want to update only a single
resources attribute and in this case the users email, as well as still
be able to validate this attribute with the model? Is it possible to
do this with the restful code supplied with scaffold_resource?

To do a partial update, the convention explained in the article,
unless I am not understanding, would be to update via a URL /user/1/

It also talks about scope. But how? I am lost on this. How would the
route be defined for this? Would this require a new method? What would
this new method look like? Thanks in advance to anyone who would find
this topic useful to contribute too.

I haven't read the PDF (link broken), but life needn't be so complex.
Partial resource representations are fine with PUT requests. The spec
leaves room to treat it as overwriting an existing resource with a new
one or as a destructive merge of one representation of an existing
resource onto another.

Rails treats PUT as a merge since it's simple, flexible, and
forgiving. Check out the scaffolding on edge: PUT /users/1?email=foo
works as you'd expect.


Here is the link. Guess it was broken.

Cool. I wish I had attended that talk; looks like fun!

Scott mentions the ambiguity in PUT semantics-- whether the resource
representation that you PUT should be returned on the next GET-- and
mentions that he prefers to a looser interpretation leaving it up to
the existing resource to decide what to do with the request.

So using PUT to update part of a resource is fine. The alternative is
explicitly addressing those parts and updating them in whole. So it's
a question of where you want to make that partition: in its address or
in its content.

I think making the cut on content rather than address yields a
resource with less surface area that's easier to understand and use.

So, form_for(@user, :method => :put) will render a form that does a
PUT /users/123 request.

The map.resources :users routes map PUT /users/:id to
UsersController#update, so @user.attributes = params[:user] there as
usual, and you're golden.


dear sender,
i�m out of the office until may 29th.
your email will not be forwarded.
for urgent stuff please contact
kind regards,