Method: Cyrax::Extensions::HasService#update

Defined in:
lib/cyrax/extensions/has_service.rb

#update(custom_attributes = nil, &block) ⇒ Cyrax::Response Also known as: update!

Updates a single item and persists to DB Used for :update action in controller

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cyrax/extensions/has_service.rb', line 60

def update(custom_attributes = nil, &block)
  resource = repository.build(resource_params_id)
  old_resource = resource.dup
  set_resource_attributes(resource, custom_attributes||resource_attributes)
  authorize_resource!(:update, resource)
  transaction do
    if repository.save(resource)
      set_message(:updated)
      block.call(resource, old_resource) if block_given?
    end
  end
  respond_with(resource)
end