-1

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

alex D
  • 66
  • 4

1 Answers1

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