I am using activeresource model, I need to consume API which supports only patch request method call for updating resource. How to override the update call in Active resource model? Please advise
Asked
Active
Viewed 425 times
-1
-
Can you show what you did so far? – tversteeg Mar 10 '15 at 13:40
-
@tversteeg: Added following method in Model 'def update connection.patch(element_path(prefix_options), encode, self.class.headers).tap do |response| load_attributes_from_response(response) end end' – alex D Mar 10 '15 at 13:48
-
This question has nothing to do with ActiveRestClient... – Andy Jeffries May 06 '15 at 11:47
-
@AndyJeffries Indeed it was related to ActiveRESTClient. Suggested solution below. – alex D Jul 09 '20 at 06:37
1 Answers
0
Figured it out myself.
Following code did the trick. Sent those parameters which are supposed to be updated only. Removed all other parameters from request.
def update
data = JSON.parse(encode)
data_to_send = data.select{|k,v| ["name", "surname"].include?(k)}
run_callbacks :update do
connection.patch(element_path(prefix_options), data_to_send.to_json, self.class.headers).tap do |response|
load_attributes_from_response(response)
end
end
end

alex D
- 66
- 4