ruby-on-railsruby

How to prepare updated attributes hash for update external service


I want to achive something like below. How to get new_attributes hash?

after_save :update_asterisk_contact

def update_asterisk_contact
  changes # => [{ "sip_id"=>[334, 355], "updated_at"=>[Tue, 29 Oct 2013 16:03:17 CET +01:00, Tue, 29 Oct 2013 16:08:31 CET +01:00]}]
  # new_attributes => {'sip_id'=> 355}
  client = Asterisk::Client.instance
  client.update(self.id, new_attributes)
end

Solution

  • If I understand you correctly, you only need to use attributes method:

    def update_asterisk_contact
      client = Asterisk::Client.instance
      client.update(id, attributes)
    end