Validate a resource and save (POST) it to the remote web service. If any
local validations fail - the save (POST) will not be attempted.
# File activeresource/lib/active_resource/validations.rb, line 71
def save_with_validation(options=nil)
perform_validation = case options
when Hash
options[:validate] != false
when NilClass
true
else
ActiveSupport::Deprecation.warn "save(#{options}) is deprecated, please give save(:validate => #{options}) instead", caller
options
end
# clear the remote validations so they don't interfere with the local
# ones. Otherwise we get an endless loop and can never change the
# fields so as to make the resource valid
@remote_errors = nil
if perform_validation && valid? || !perform_validation
save_without_validation
true
else
false
end
rescue ResourceInvalid => error
# cache the remote errors because every call to <tt>valid?</tt> clears
# all errors. We must keep a copy to add these back after local
# validations
@remote_errors = error
load_remote_errors(@remote_errors, true)
false
end