# RESTful RESOURCE PARTIAL UPDATE (Single Attribute Update)

**URL:** <https://www.ruby-forum.com/t/restful-resource-partial-update-single-attribute-update/104772>\
**Category:** Rails\
**Created:** [May 22, 2007, 11:54am UTC](https://www.ruby-forum.com/t/restful-resource-partial-update-single-attribute-update/104772 "2007-05-22T11:54:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lambo4jos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8baadc/32.png) [@lambo4jos](https://www.ruby-forum.com/u/lambo4jos)\
**Post date:** [May 22, 2007, 11:54am UTC](https://www.ruby-forum.com/t/restful-resource-partial-update-single-attribute-update/104772/1 "2007-05-22T11:54:52Z")

</div>

I am having a hard time understanding updating a partial resource.  
This was talked about at railsconf here on page 29.  
[http://www.web2expo.com/presentations/r](http://www.web2expo.com/presentations/r) … \_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/  
email.

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.

---

<div class="post-metadata">

**Author:** ![lambo4jos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8baadc/32.png) [@lambo4jos](https://www.ruby-forum.com/u/lambo4jos)\
**Post date:** [May 22, 2007, 12:20pm UTC](https://www.ruby-forum.com/t/restful-resource-partial-update-single-attribute-update/104772/2 "2007-05-22T12:20:54Z")

</div>

On 5/22/07, lambo4jos [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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/  
> email.
> 
> 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.

jeremy

---

<div class="post-metadata">

**Author:** ![lambo4jos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8baadc/32.png) [@lambo4jos](https://www.ruby-forum.com/u/lambo4jos)\
**Post date:** [May 22, 2007, 12:21pm UTC](https://www.ruby-forum.com/t/restful-resource-partial-update-single-attribute-update/104772/3 "2007-05-22T12:21:54Z")

</div>

[http://www.web2expo.com/presentations/rails2007/raymond\_scott.pdf](http://www.web2expo.com/presentations/rails2007/raymond_scott.pdf)

Here is the link. Guess it was broken.

---

<div class="post-metadata">

**Author:** ![lambo4jos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8baadc/32.png) [@lambo4jos](https://www.ruby-forum.com/u/lambo4jos)\
**Post date:** [May 22, 2007, 12:38pm UTC](https://www.ruby-forum.com/t/restful-resource-partial-update-single-attribute-update/104772/4 "2007-05-22T12:38:56Z")

</div>

On 5/22/07, lambo4jos [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [http://www.web2expo.com/presentations/rails2007/raymond\_scott.pdf](http://www.web2expo.com/presentations/rails2007/raymond_scott.pdf)
> 
> 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.

jeremy

---

<div class="post-metadata">

**Author:** ![lambo4jos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8baadc/32.png) [@lambo4jos](https://www.ruby-forum.com/u/lambo4jos)\
**Post date:** [September 25, 2007, 11:01pm UTC](https://www.ruby-forum.com/t/restful-resource-partial-update-single-attribute-update/104772/5 "2007-09-25T23:01:10Z")

</div>

dear sender,  
i´m out of the office until may 29th.  
your email will not be forwarded.  
for urgent stuff please contact removed\_email\_address@domain.invalid  
kind regards,  
alexander
