Steve,

Thanks for your response!

If you plan to use PATCH, you should figure out what you need and use it.
>

I had read: 
http://weblog.rubyonrails.org/2012/2/25/edge-rails-patch-is-the-new-primary-http-method-for-updates/

It states that:

Because of that, the PATCH <http://www.rfc-editor.org/rfc/rfc5789.txt>method 
was defined in 1995 and standarized later. PATCH is a method that is 
> not safe, nor idempotent, and allows *full and partial updates* and 
> *side-effects 
> on other resources*. In practice, as you see, PATCH suits everyday web 
> programming way better than PUT for updating resources. In Ruby on Rails it 
> corresponds naturally to the way we use update_attributes for updating 
> records. Thus, PATCH is going to be the primary method for updates in Rails 
> 4.0.
>

Rails supports use of accepts_nested_attributes_for to update associated 
models, so I'm curious how these patches could be accomplished easily in 
Rails 4:

1. What would a JSON request look like that could be sent into a controller 
via patch method to only change one field in an associated model, where the 
model being updated accepts_nested_attributes_for the model that has the 
field you want to update?

2. What would a JSON request look like that could be sent into a controller 
via patch method to only remove a single tie record to an association 
without changing the list of associations, to avoid losing other changes 
that have been made to the membership of the collection/list of 
associations? (Does patch require a _destroy on a tie/connecting model? If 
so, would that be bad terminology considering that changes to associations 
as pointed out in http://guides.rubyonrails.org/association_basics.html for 
the Appointment tie models between Physician and Patient is deleted and not 
destroyed when there is a has_many :through relationship and the membership 
list is updated? In that case would a new _remove key on the associated 
model make sense?)

I'm basically just trying to understand what Rails 4 plans to offer with 
regard to patching, especially in the context of Javascript frameworks and 
the like that would be wanting to send/receive JSON to Rails controllers to 
manage not only models, but models and their associations. Just changing 
each model via its own request requires more requests and if there are 
changes that need to be made to specific fields of a model and specific 
fields of its associations in a single transaction, it would be much easier 
to just being able to send in a single patch request to a model that 
defines accepts_nested_attributes_for.

Thanks!
Gary


On Monday, August 13, 2012 6:20:25 PM UTC-4, Steve Klabnik wrote:
>
> This is the reason that the spec for patch[1] specifically requires a 
> diff be sent[2]: 
>
> > The set of changes is represented in a format called a "patch 
> > document" identified by a media type. 
>
> and 
>
> > With PATCH, however, the enclosed entity contains a set 
> > of instructions describing how a resource currently residing on the 
> > origin server should be modified to produce a new version. 
>
> and 
>
> > Further, it is expected that different patch document formats will be 
> > appropriate for different types of resources and that no single 
> > format will be appropriate for all types of resources.  Therefore, 
> > there is no single default patch document format that implementations 
> > are required to support. 
>
> If you plan to use PATCH, you should figure out what you need and use 
> it. I'm not aware of a media type that does diffs in plain JSON at 
> this time. 
>
> 1: http://tools.ietf.org/html/rfc5789 
> 2: http://tools.ietf.org/html/rfc5789#section-2 
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-core/-/YfYQDwoTeB0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to