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 ... _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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeremy Kemper
2007-May-22 10:20 UTC
Re: RESTful RESOURCE PARTIAL UPDATE (Single Attribute Update)
On 5/22/07, lambo4jos <josephannuzzi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 ... _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.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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
lambo4jos
2007-May-22 10:21 UTC
Re: RESTful RESOURCE PARTIAL UPDATE (Single Attribute Update)
http://www.web2expo.com/presentations/rails2007/raymond_scott.pdf Here is the link. Guess it was broken. On May 22, 2:47 am, lambo4jos <josephannu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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... _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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeremy Kemper
2007-May-22 10:37 UTC
Re: RESTful RESOURCE PARTIAL UPDATE (Single Attribute Update)
On 5/22/07, lambo4jos <josephannuzzi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
alexander-0M91wEDH++c@public.gmane.org
2007-May-22 10:39 UTC
Re: RESTful RESOURCE PARTIAL UPDATE (Single Attribute Update)
dear sender, i´m out of the office until may 29th. your email will not be forwarded. for urgent stuff please contact joern-0M91wEDH++c@public.gmane.org kind regards, alexander --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---