Method: Fera::Base#update

Defined in:
lib/fera/models/base.rb

#update(changed_attributes, extra_params = {}, raise: false) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/fera/models/base.rb', line 152

def update(changed_attributes, extra_params = {}, raise: false)
  run_callbacks(:update) do
    connection.put(element_path(prefix_options, extra_params), changed_attributes.to_json, self.class.headers).tap do |response|
      load_attributes_from_response(response)
    end

    load(changed_attributes)
  end

  true
rescue ActiveResource::ConnectionError => e
  set_last_response(e)

  if raise
    raise(ActiveResource::ResourceInvalid.new(last_response, last_response_message.presence))
  end

  false
end